Tugger the SLUGger!SLUG Mailing List Archives

Re: [chat] prob with regex


Ah Zhasper solved my problem. Here is his solution (posted to me so I 
hope its ok to cc here).

> <quote who="Michael Lake">
>> I am having some minor prob with a regex - I think my first .* is 
>> gobbling up the remainder of the expression.
>> I have a text file like this:
>> PAVEY AUASF020388
>> PAVEY,A AUASF02389
>> PAVEY,A AUASF02390       <-- just a comma then A
>> PAVEY,A. AUASF02391      <-- this one has a full stop
>> and I am matching the string PAVEY followed by anything then ONE white 
>> space then a string starting with AUASF that I want to remember

Zhasper wrote....
> this is where you're going wrong..
> You don't want "anything then ONE white space", what you're actually 
> looking
> for is "anything that isn't white space, followed by ONE white space"
>> s/PAVEY.* \(AUASF.*\)/AUASF00899 \1/
> 
> This thinking error leads to an error in your regexp..
> what you really want is
> 
> s/PAVEY[^\ ]* \(AUASF.*\)/AUASF00899 \1/

Nearly there. I just had to remove the space after the first * i.e.
 > s/PAVEY[^\ ]*\(AUASF.*\)/AUASF00899 \1/

My prob was that:
>> My prob is that sed script above is not replacing the PAVEY.*
>> I gather I cant use two '.*'s

and Zhasper had it right.....
> Quite right. regexp is greedy. you tell it .*, it grabs the largest string
> it can find that can match .*

Thanks Zhasper and I'll checkout what that text2regex is Tony.

-- 
Mike Lake
Uni of Technol., Sydney



UTS CRICOS Provider Code:  00099F

DISCLAIMER
========================================================================
This email message and any accompanying attachments may contain
confidential information.  If you are not the intended recipient, do not
read, use, disseminate, distribute or copy this message or attachments.
If you have received this message in error, please notify the sender
immediately and delete this message. Any views expressed in this message
are those of the individual sender, except where the sender expressly,
and with authority, states them to be the views the University of
Technology Sydney. Before opening any attachments, please check them for
viruses and defects.
========================================================================