Skip to main content.
home | support | download

Back to List Archive

RE: regex help :0)

From: stuart <stuart(at)not-real.mohawk.net>
Date: Fri May 08 1998 - 11:53:14 GMT
Thanks to all of you who took the time to help me with my regex
problem!(recap: how to add "field=" to a list of search words while
skipping all booleans)

FYI, I saw many different approaches to the problem but the one I like
best is this sweet one liner(Perl):

>s/(\b(?!and\b|n?or\b)\S+(?:\s|$))/field=$1/g

Here it is in practice
>
>:r! echo andy and cor or ignore nor luthor | perl -wpe \
>        's/(\b(?!and\b|n?or\b)\S+(?:\s|$))/field=$1/g'
>field=andy and field=cor or field=ignore nor field=luthor
>
>The hip owls book should help you understand *what* I did and why. :^)
>
>Elijah

Thanks Elijah.

BTW, the "regex bible" I mentioned is Mastering Regular Expressions by
Jeffrey E. F. Friedl which can be had at:

http://www.amazon.com/exec/obidos/ats-query/002-1303108-7682469

for $23.96. The reviews convinced me to let my employer buy it for me
:o)  .

-Stuart
Received on Fri May 8 04:54:45 1998