Regular expression assistance
I am trying to write a small app that looks at files in a folder, and base don the name, performs an operation.
An example of a file would be:
CSI Miami S04E21 720p HDTV X264-DIMENSION.avi
What that is, is a TV show called CSI Miami... it's Season 4, Episode 21, and it's a 720p version.
I have a regular expression like this:
.?CSI.+?Miami.+?720p.?
But this failed.
What I thought it said was, 'Any string with CSI AND Miami AND 720p. However, it never works. It seems to require all the words are together. But because the filename has the S04E21 in it, the regex is failing .. I think.
Can 开发者_StackOverflow中文版you spot an error?
Depending on your flavor of regex and how you're matching, you could have any number of issues, but you'll probably want to start with this:
.*?CSI.+?Miami.+?720p.*
This will match up to the beginning and end of the file name, in case what you're calling with is trying to match the entire string.
(?=.*CSI)(?=.*Miami)(?=.*720p)
or
(?=[\S\s]*CSI)(?=[\S\s]*Miami)(?=[\S\s]*720p)
精彩评论