in reply to regexp pattern match help?
Notice the [^\B#] idiom, what it means is that I want a character set of \B, non-word boundary, and #, and then take the compliment of the set. So the result will be a word boundary that does not match on the # character.my $str = "This is a line # with comment"; my $word = '#'; while ($str =~ /[^\B#]($word)[^\B#]/g) { print "$1\n"; } __OUTPUT__ #
my $str = "This is a line # with comment Boss."; my $word = "#"; # define custom \b my $b = qr/(?:(?=\S)(?<!\S)|(?!\S)(?<=\S))/; # and match on non-space characters while ($str =~ /$b(\S+)$b/g) { print "$1\n"; } # or ignore the boundaries completely and match on non-space character +s while ($str =~ /(\S+)/g) { print "$1\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regexp pattern match help?
by Abigail-II (Bishop) on Dec 03, 2003 at 01:20 UTC | |
by Elijah (Hermit) on Dec 03, 2003 at 06:52 UTC | |
by ysth (Canon) on Dec 03, 2003 at 07:35 UTC |