On 2/12/06, Ley, Chung <[EMAIL PROTECTED]> wrote: > Hi, > > What is the regular expression to look for "%" unless that the "\" is right > before that? > > So, if I have something like this: > "\%abc%", I like to get the 2nd "%" and not the first.... > > Thanks... > > --Chung
Your first resource for regex info should be perlre (man perlre, perldoc perlre, or http://perldoc.perl.org/perlre.html) Here is the relevant info from it: (?!pattern) (?!) look-ahead, negative lookahead, negative A zero-width negative look-ahead assertion. For example /foo(?!bar)/ matches any occurrence of "foo" that isn't followed by "bar". Note however that look-ahead and look-behind are NOT the same thing. You cannot use this for look-behind. If you are looking for a "bar" that isn't preceded by a "foo", /(?!foo)bar/ will not do what you want. That's because the (?!foo) is just saying that the next thing cannot be "foo"--and it's not, it's a "bar", so "foobar" will match. You would have to do something like /(?!foo)...bar/ for that. We say "like" because there's the case of your "bar" not having three characters before it. You could cover that this way: /(?:(?!foo)...|^.{0,2})bar/ . Sometimes it's still easier just to say: if (/bar/ && $` !~ /foo$/) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>