From: Mark Hubbart Date: 2005-01-18T07:51:37+09:00 Subject: Re: My regexp stupidity needs assistance before loose all my hair! On Tue, 18 Jan 2005 07:31:06 +0900, Assaph Mehr wrote: > > I had an escape character match in the regexp: > > > > / [^`] \[(.+?)\] /x > > > > That was messing it up (Don't really know why) but I just "zeroed" > it: > > > > / (?=[^`]) \[(.+?)\] /x > > > > And that did the trick. > > Thats because [^`] will match 'a single character that is not `'. > When you did the zero-width lookahead, you made into 'possibly a > character, so long as it's not ` '. I may be reading this wrong, but I think that with the zero-width lookahead, it is now ensuring that the first character of the match is not a backtick. Which, since it's always going to be a square bracket, makes the lookahead superfluous. If you need escaping, try: /(?: # escape sequence match ^ | [^`] # alternate: match either "start of line" or a non-backtick. ) ( # non-greedy [foo] match \[.*?\] )/ ... then use $1. This one won't match any paired square brackets immediately preceded by a backtick. cheers, Mark