[nzlug] Hard regexp question
Jim Cheetham
jim at gonzul.net
Fri Aug 3 22:50:55 NZST 2007
Having a difficult moment with regexps, and don't have my book handy ...
How can I say "something as long as it isn't this thing" within a
regexp? (i.e. without looking at the match outside the regexp)
I'm trying to match a delimited range of text, let's say delimited
with " marks for arguments sake. I'd like to get "WORD" or "TWO WORDS"
but not _just_ spaces - " "
/"(.+?)"/ works quite well generally (I'm using a non-greedy match in
Ruby, hence the ?), and yes it will match "s within the group, such as
"fred"was" but that's OK.
I can't exclude spaces from the pattern (by substituting the .)
because that means no spaces are allowed ... /"([^ ]+?)"/
I think I need something in the negative lookahead style with ?! but I
haven't figured those out properly yet ...
-jim
More information about the NZLUG
mailing list