in reply to Another regex to solve ...

local $_= "Stop tip stoop put up, tops steep 'creap' sleep soap!"; my @words; push @words, $1 # while /(\b\w*(?!(.)\2)\w[aeiou]p\b)/g; while /(\b(?:\w*(?!(.)\2)\w)?[aeiou]p\b)/g; print "( @words )\n"; __END__ ( Stop tip up creap soap )

Update: Changed . to \w so would not match, for example, "no-op" (if you want '-' allowed in words, then replace \w with, for example, [-\w] both places). Then: added (?:...)? to match two-letter words (since my original attempt that handled two-letter words fails because (?<!\2) is not smart enough to realize the fixed length of \2).

- tye        

Replies are listed 'Best First'.
Re^2: Another regex to solve ... (more \2)
by tye (Sage) on Aug 18, 2011 at 19:26 UTC

    Here are some other ways to do it, including one that doesn't work and one that almost works...

    local $_= "Up stop 'Oop' tip stoop put\nup, tops steep 'creap' sleep s +oap!"; my @words; push @words, $1 # Misses "up" if first word in string: # while /(\b\w*(?<=(.))(?!\2)[aeiou]p\b)/gi; # Would work if (?<=...|...) were smarter: # while /(\b\w*(?<=^|(.)(?!\2))[aeiou]p\b)/gsi; # How to work around (?<=...|...) being dumb: # while /(\b\w*(?:(?<=^)|(?<=(.)(?!\2)))[aeiou]p\b)/gsi; # (?<=^) can be shortened to just ^: while /(\b\w*(?:^|(?<=(.)(?!\2)))[aeiou]p\b)/gsi; # Or just skip the complex check for 2-letter words: # while /(\b(?:\w*(?<=(.))(?!\2))?[aeiou]p\b)/gsi; print "( @words )\n"; __END__ ( Up stop tip up creap soap )

    - tye