in reply to RegEx to match at least one non-adjacent term
Updated: to handle parentheses.
#!/usr/bin/env perl use warnings; use strict; while (<DATA>) { #my @no_reds = grep { !/^r/i } split; my @no_reds = grep { !/^r/i } split /[\s\(\)]/; print "@no_reds\n"; } __DATA__ 12345 Gray 6789 Red rd 555 blue 888 red 777 green 999 foo bar r baz ruby goo(r) ruby doobie 888red999
Prints out:
12345 Gray 6789 555 blue 888 777 green 999 foo bar baz goo doobie 888red999
Unlike ikegami's solution, this requires the input to be whitespace-separated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RegEx to match at least one non-adjacent term
by Cefu (Beadle) on Dec 07, 2007 at 17:12 UTC |