Which gives the following on various runs: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; }
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.$ 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
---
s;;:<).>|\;\;_>?\\^0<|=!]=,|{\$/.'>|<?.|/"&?=#!>%\$|#/\$%{};;y;,'} -/:-@[-`{-};,'}`-{/" -;;s;;$_;see;
Warning: Any code posted by tuxz0r is untested, unless otherwise stated, and is used at your own risk.
In reply to Re: RegEx to match at least one non-adjacent term
by tuxz0r
in thread RegEx to match at least one non-adjacent term
by Cefu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |