Reputation: 3
using REMatchNoCase, how can you write a Regular Expressions to find in a string the following
S##E## or S##E##E## ... sample S01E01 or S07E16E17
S and E can be upper or lower case and there can be spaces, such as S 01 E01
thank you
Upvotes: 0
Views: 158
Reputation: 29870
Try this:
matches = reMatchNoCase("S\d{2}(?:E\d{2}){1,2}", string);
Update: Leigh is quite right in his comment that I missed the bit of the requirement wherein optional spaces could be present. Although the requirement is not clear as to where the spaces might validly be present. To respect the example exactly as stated, the regex would be adjusted to:
S\s*\d{2}(?:E\d{2}){1,2}
(note the inclusion of \s*, meaning zero or more whitespace characters). If there are more positions the spaces might appear, just insert \s* in those positions too.
Upvotes: 1
Reputation: 582
here's the regular expression you'll need: "(?i)(^S\d{2}E\d{2}$)|(^S\d{2}E\d{2}E\d{2}$)"
Upvotes: 0