in reply to Re-define Word Boundary?
What I'd like to do is redefine what "\b" is.
You can, by overloading regular expressions. The following is just a quick hack I threw together, but I think it catches most cases, including /[\b]/ and /\\b/.
#!/usr/bin/perl use strict; use warnings; no warnings qw /syntax/; BEGIN { my $B = '(?:(?<=[\w/])(?=[^\w/])|' . '(?<=[^\w/])(?=[\w/])|' . '^(?=[\w/])|(?<=[\w/])$)'; $^H |= 0x30000; $^H {qr} = sub { local $_ = $_ [1]; s/(\[\^?]?[^]]*]|[^\\]+|\\.)/$1 eq '\b' ? $B : $1/eg; $_; } } while (<DATA>) { chomp; print "$_: "; print $& if /\b\w+\b/; print "\n"; } __DATA__ foo &foo& &foo/bar& foo: foo &foo&: foo &foo/bar&:
Abigail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re-define Word Boundary?
by ysth (Canon) on Nov 21, 2003 at 01:05 UTC |