Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: regular expression help

by amphiplex (Monk)
on Jul 17, 2002 at 16:38 UTC ( [id://182499]=note: print w/replies, xml ) Need Help??


in reply to regular expression help

This should do the job:
my @results; while (<>) { if (/^N\d+\s+\*(.*)/) { push @results, "!$1"; } else { push @results, /[XYZ]([-+]*[\d\.]+)/g; } } print join ' ',@results;
The first regex handles comment lines, the second one greps all occurances of either an X,Y or Z followed optionally by a negative or positive sign followed by a combination of digits and dot.

If there is only one comment line on the top of each file, you could do this faster, but for a couple of thousand lines it should not matter.

update: the code was wrong, I forgot the * after the sign match.

---- amphiplex

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://182499]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2025-03-28 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (71 votes). Check out past polls.

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.