in reply to To find, this not preceded by that, use negative look-behind with negative look-ahead , use (?<!pattern) with (?!pattern), (?<!pattern)(?!pattern)

The (?<!bar) in your "solution" does nothing. s/\b((?!bar)\S{3,})/\U$1/g behaves the same. The only way for (?<!bar) to matter is due to \b caring about \w vs \W not about \s vs \S. \b\w{3,} would imply (?<!\w) which implies (?<!bar).

I can't tell what you are actually trying to solve so I don't have much else to offer. Would "foobar" be "\S{3} not preceded by 'bar'"? Is that what you are trying to find?

- tye        

Replies are listed 'Best First'.
Re^2: To find, this not preceded by that, use (?<!pattern)(?!pattern) (or not)
by Anonymous Monk on Dec 13, 2011 at 15:33 UTC

    Would "foobar" be "\S{3} not preceded by 'bar'"? Is that what you are trying to find?

    Yes it would. I thought this much was clear.

    I see now the wording of (?!pattern) is what confused me

    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. Use look-behind instead (see below).

    And I'm certain now, that I only tried s/((?!bar)\S{3,})/\U$1/g ; without \b

Re^2: To find, this not preceded by that, use (?<!pattern)(?!pattern) (or not)
by Anonymous Monk on Dec 13, 2011 at 15:08 UTC

    And here I could have sworn I tried that

    THANKS!