in reply to RegEx to match at least one non-adjacent term

Not sure what your input looks like, but just testing with your string above this seems to work for me:
use strict; while (<STDIN>) { s/[\s\(\)]+//g; # strip optional chars my @matches = m/(\d+)|([^\d]+)/g; print join ":", grep { defined $_ and $_ !~ m/^(r|rd|red)$/i } + @matches; }
Which gives the following on various runs:
$ echo "12345 (Gray) 6789 (Red)" | ./red.pl 12345:Gray:6789 $ echo "12345 (Gray) 6789 Red" | ./red.pl 12345:Gray:6789 $ echo "12345Gray6789Red" | ./red.pl 12345:Gray:6789
Update: Ikegami pointed out that I missed the requirement that spaces/parens were optional, so I changed this around slightly (no longer just a one liner). Now we can just get the numbers and words out seperately and print them in order skipping any words (like variations of red) that you need.

---
s;;:<).>|\;\;_>?\\^0<|=!]=,|{\$/.'>|<?.|/"&?=#!>%\$|#/\$%{};;y;,'} -/:-@[-`{-};,'}`-{/" -;;s;;$_;see;
Warning: Any code posted by tuxz0r is untested, unless otherwise stated, and is used at your own risk.

Replies are listed 'Best First'.
Re^2: RegEx to match at least one non-adjacent term
by ikegami (Patriarch) on Dec 07, 2007 at 16:26 UTC
    Doesn't work?
    $ echo "12345Red6789" | perl -ape 's/[\s\(]+(r|rd|red)[\s\)]+//gi;' 12345Red6789

    The OP said the spaces were optional.