in reply to Regex solution needed

Where did you get the idea that perl regexes do not have a look-behind? perlre describes both positive and negative look-behinds.

/(?<!game)cocks/

matches an occurrence of cocks that does not follow game, but I'm sure someone with stronger regex-fu will provide a more complete solution.

Bear in mind that your solution does not capture all possible non-vulgar use of cock(s). How about fighting cocks or cock-a-doodle-doo? A popular cheer at South Carolina football games (I am told) is "Hey, how 'bout them cocks!".

Replies are listed 'Best First'.
Re^2: Regex solution needed
by imp (Priest) on Feb 23, 2007 at 16:50 UTC
    Look-behind is supported but not for variable length patterns, e.g. (?<!game|the)\s+cocks will not work.

    The best solution IMO is to just allow the word 'cocks'.

Re^2: Regex solution needed
by spivey3587 (Acolyte) on Feb 23, 2007 at 17:01 UTC
    Doh! I was a little mis-guided--my Mastering Regular Expressions book say on page 229 'Lookbehind, were it supported, would somehow look back to toward the left'. Turns out the book published in 1999, so shame on me for not checking further.

    Your're correct in that it doesn't cover all possibilities, and that's something I still have to consider. I just got sidetracked with the problem at hand and wanted to address it for the learning experience. Thanks for pointing me in the right direction with lookbehind.