从ruby正则表达式中的字符串中提取数字
我有一根绳子 青少年妈妈2(第五季)| Ep。7 |现在是| MTV的日子 我只需要从中提取季号和集号。即5号和7号从ruby正则表达式中的字符串中提取数字,ruby,regex,Ruby,Regex,我有一根绳子 青少年妈妈2(第五季)| Ep。7 |现在是| MTV的日子 我只需要从中提取季号和集号。即5号和7号 请提供帮助。使用字符串。扫描功能如下所示 > "Teen Mom 2 (Season 5) | Ep. 7 | These Are The Days | MTV".scan(/(?<=Season )\d+|(?<=Ep\. )\d+/) => ["5", "7"] “青少年妈妈2(第五季)| Ep.7 |这是MTV的日子”。扫描(/(?使用字符串。扫描
请提供帮助。使用
字符串。扫描功能如下所示
> "Teen Mom 2 (Season 5) | Ep. 7 | These Are The Days | MTV".scan(/(?<=Season )\d+|(?<=Ep\. )\d+/)
=> ["5", "7"]
“青少年妈妈2(第五季)| Ep.7 |这是MTV的日子”。扫描(/(?使用字符串。扫描
功能如下
> "Teen Mom 2 (Season 5) | Ep. 7 | These Are The Days | MTV".scan(/(?<=Season )\d+|(?<=Ep\. )\d+/)
=> ["5", "7"]
>“青少年妈妈2(第五季)| Ep.7 |这是几天| MTV”。扫描(/(?以下是生成命名匹配的方法:
txt = "Teen Mom 2 (Season 5) | Ep. 7 | These Are The Days | MTV"
match = /Season (?<season>\d+).*Ep\. (?<ep>\d+)/.match txt
match['season']
# => 5
match['ep']
# => 7
txt=“青少年妈妈2(第五季)|第七集|这是MTV的日子”
match=/seasure(?\d+).*Ep\(?\d+)/.match-txt
比赛[季节]
# => 5
匹配['ep']
# => 7
以下是一个生成命名匹配的方法:
txt = "Teen Mom 2 (Season 5) | Ep. 7 | These Are The Days | MTV"
match = /Season (?<season>\d+).*Ep\. (?<ep>\d+)/.match txt
match['season']
# => 5
match['ep']
# => 7
txt=“青少年妈妈2(第五季)|第七集|这是MTV的日子”
match=/seasure(?\d+).*Ep\(?\d+)/.match-txt
比赛[季节]
# => 5
匹配['ep']
# => 7
或(?:Season | Ep\)\s+\K\d+
回答好,很好\Komment。或(?:Season | Ep\)\s+\K\d+
回答好,很好\Komment。