In Ruby, I'm trying to extract from text a string that starts开发者_如何学JAVA with "who" and ends with the first of either a ")" or "when" (but doesn't include the ")" or the "when").
I've tried the following:
who.*(?=when\b|\))
which fails the case where it finds both a "when" and a ")".
Any ideas?
Many thanks
You need to make your .*
part non-greedy.
Try this regex :
who.*?(?=when\b|\))
(who.*?)(when|\))
That should do it I think. $1 will be your string.
精彩评论