Reputation: 6332
I have a pattern
blah_blah_blah_blah_19292_blah_m32.jpg
I want to match everything up to _mXX while excluding the _mXX.
I have ^(.*[_m])
but this is inclusive. Can't seem to get the capture group excluded. What am I missing?
rubular link http://www.rubular.com/r/0Ls12Z6GH7
Upvotes: 1
Views: 96
Reputation: 784958
You can use positive lookahead for that:
/^.*?(?=_m[0-9]+)/
Will match blah_blah_blah_blah_19292_blah
in your input string.
Quoting from above link:
q(?=u)
matches a q that is followed by a u, without making the u part of the match. The positive lookahead construct is a pair of parentheses, with the opening parenthesis followed by a question mark and an equals sign.
Upvotes: 2