Ray Jette wrote:
Thanks for all the help. I am still having issues. Let me try to explain a little more. Subjects can contain the following
PO <random #s>
PO<random #s>
PO# <random #s>
PO#<random #s>
PO # <random #s>
PO #<random #s>

I can match PO with /\bPO/i but this does not fill my requirements.
I need to be able to match all above and i'm not sure where to start.

Thank you for any help you may provide.

/\bPO ?\#? ?[0-9]*\b/i

or

/\bPO\s?\#?\s?[0-9]*\b/i

just construct what you want, step by step. If you want PO not to be contained within anything else (except the possible numbers following), then you want the word boundary at the beginning and end. If you want a single space, do that, if you want any white space, then allow that. The "?" gives you that character optionally, and the "*" gives you any number of (including 0) of the digits. So, that ought to do it. Then, of course, you have to incorporate it into your perl snippet.


I tried the first of these in the following simple script (named ignore.pl):

#! /usr/local/bin/perl -w
# Routine to ignore "normal" log entries - after Marcus Ranum's "artifical
# ignorance"
#
       while (<>)
       {
         if (/\bPO ?\#? ?[0-9]*\b/i) { next }
         else {print}
       }



The script is put to use as follows:

# cat | ./ignore.pl

After that, I could type anything I wanted. If it matched, it would be ignored. If it didn't it would print it back out. I matched all your examples, including the lower case.

For example:

PO
lskdfjs
lskdfjs
this is in regard to po #2
this regardsPO234
this regardsPO234
can you grab me a PO 234
what about po#345?
what about that PO

where the non-matches got spat back at me.

Then you can play around a bit. Since the " " and "#" count as word boundaries, you can cut them out and use:

/\bPO\b|\bPO[0-9]\b/i

which works as well.

For reference, I have that script in my /var/adm/ directory. I routinely toss several regeps in it and use it when I'm scanning log files to filter out the commonly occurring lines I don't want to be bothered by. It helps focus in on the oddities.



--
---------------

Chris Hoogendyk

-
  O__  ---- Systems Administrator
 c/ /'_ --- Biology & Geology Departments
(*) \(*) -- 140 Morrill Science Center
~~~~~~~~~~ - University of Massachusetts, Amherst
<[EMAIL PROTECTED]>

---------------
Erdös 4


Reply via email to