Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

How to set a delimiter. (Moved from Q&A)

by Russ (Deacon)
on Dec 09, 2000 at 11:15 UTC ( [id://45870]=perlquestion: print w/replies, xml ) Need Help??

Russ has asked for the wisdom of the Perl Monks concerning the following question:

This post was moved from Categorized Questions and Answers
Please do not vote for this node. It will affect the wrong user.
Thank You -- Q&AEditors

I want to have a regex that searches for data (hi | lo) and end at a "°F" sign in between that are digits.I want to match this. hi 37°F lo 27°F. I tried this...

if($info =~ /(hi|lo)\s+[-]\d{1,3}°F/i){ ...#do crapppppp }
It isn't working.. HELP! thanks

Replies are listed 'Best First'.
Re: How to set a delimiter. (Moved from Q&A)
by chromatic (Archbishop) on Dec 09, 2000 at 12:02 UTC
    I'm not sure what the character class with the hyphen in there is for. Do you want to capture the temperatures, too? If so, here's what I'd try:
    if ($info =~ /(hi|lo)\s+(\d{1,3}).F/i) { # do something with $1 and $2 }
    You were on the right track... but the square brackets puzzle me.

    Update: jlp suggests that temperatures may be negative, in which case it makes lots of sense. Here's the revision to allow that:

    if ($info =~ /(hi|lo)\s+(-?\d{1,3}).F/i) { # do something with $1 and $2 }
    The ? means the hyphen may or may not be present. If it is, it will be grouped with the digits and stored in $2.
Re: How to set a delimiter. (Moved from Q&A)
by I0 (Priest) on Dec 14, 2000 at 17:24 UTC
    Were you trying to say [-+]?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found