in reply to Re^3: Defining Characters in Word Boundary?
in thread Defining Characters in Word Boundary?
In your case, (?![a-z]) is what you would want to use.
One behavioral difference between these regexes and, in the case of the OP, the reason iaw4 would (probably) want to use this regex is that it can match at the end of a string and thus emulates the behavior of the \b assertion. (Note: \b can also match at the start of a string.)
>perl -wMstrict -le "my $str = 'abcd'; for my $rx (qr{(?=[^a-z])}, qr{(?![a-z])}, qr{\b}) { my @offsets; push @offsets, $-[1] while $str =~ m{ ($rx) }xmsg; if (@offsets) { print qq{$rx matches '$str' at offset(s) @offsets}; } else { print qq{$rx does not match '$str'}; } } " (?-xism:(?=[^a-z])) does not match 'abcd' (?-xism:(?![a-z])) matches 'abcd' at offset(s) 4 (?-xism:\b) matches 'abcd' at offset(s) 0 4
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Defining Characters in Word Boundary?
by Jim (Curate) on Jan 21, 2011 at 01:06 UTC | |
by ikegami (Patriarch) on Jan 21, 2011 at 01:24 UTC |