Re: How to avoid this greedy match?



"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."
.



Relevant Pages

  • Re: find/replace ?
    ... regular expressions. ...
    (microsoft.public.vsnet.general)
  • Re: A subquery? Not sure if this is doable?
    ... the weekly series and the repeating monthly figure. ... 1/12/05 ABC 4.22 ... 1/12/05 DEF 3.12 ... 1/12/05 XYZ 8.88 ...
    (microsoft.public.access.queries)
  • Re: Classes as units of reuse
    ... Component ABC { ... The thing that is not clear in your pseudo code is the nature of the relationship between ABC and DEF. ... IMO, the second approach would be the best where one abstracts some set of objects with the proper functionality and then decouples their details from the rest of the application via a Facade interface to which the clients all talk. ... In the OO paradigm one basically has three levels of logical indivisibility: subsystem, object, and responsibility. ...
    (comp.object)
  • Re: A subquery? Not sure if this is doable?
    ... frequency such that the table with less frequency will repeat its value ... 1/12/05 ABC 4.22 ... 1/12/05 DEF 3.12 ... 1/12/05 XYZ 8.88 ...
    (microsoft.public.access.queries)
  • Re: A subquery? Not sure if this is doable?
    ... my computer hangs and hangs and hangs. ... 1/12/05 ABC 4.22 ... 1/12/05 DEF 3.12 ... 1/12/05 XYZ 8.88 ...
    (microsoft.public.access.queries)