Re: How to avoid this greedy match?
- From: rvtol+news@xxxxxxxxxxxx (Dr.Ruud)
- Date: Thu, 31 Jan 2008 21:49:53 +0100
"John W. Krahn" schreef:
I seem to remember that Jeffrey Friedl's[1] book describes a way to
emulate left and right word boundaries in Perl's regular expressions.
$ echo 'abc test def' |perl -wple'
$lwb = qr/\b(?=[[:alnum:]])/;
$rwb = qr/(?<=[[:alnum:]])\b/;
s/${lwb}test${rwb}/X/g;
'
abc X def
$ echo 'abc test def' |perl -wple'
$lwb = qr/(?<![[:alnum:]])(?=[[:alnum:]])/;
$rwb = qr/(?<=[[:alnum:]])(?![[:alnum:]])/;
s/${lwb}test${rwb}/X/g;
'
abc X def
(should both also work with "test" at start or end)
--
Affijn, Ruud
"Gewoon is een tijger."
.
- References:
- Re: How to avoid this greedy match?
- From: News Howardz
- RE: How to avoid this greedy match?
- From: Ajay Nagrale
- Re: How to avoid this greedy match?
- From: Yitzle
- Re: How to avoid this greedy match?
- From: John W. Krahn
- Re: How to avoid this greedy match?
- Prev by Date: Re: IO::Compress::Gzip creates empty file
- Next by Date: undefined format error
- Previous by thread: Re: How to avoid this greedy match?
- Next by thread: Re: How to avoid this greedy match?
- Index(es):
Relevant Pages
|
|