I have a string as
Teen Mom 2 (Season 5) | Ep. 7 | These Are The Days | MTV
I need to extract only Season number and Episode number from this. ie. 5 and 7.
Please help.
Use string.scan function like below.
> "Teen Mom 2 (Season 5) | Ep. 7 | These Are The Days | MTV".scan(/(?<=Season )\d+|(?<=Ep\. )\d+/)
=> ["5", "7"]
(?<=Season ) Positive look-behind asserts that the match must be preceded by Season string.\d+ Match one or more digits.(?:Season|Ep\.)\s+\K\d+