Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Matching '=' and other non alphanumeric characters using regular expressions

by MarkM (Curate)
on Dec 13, 2002 at 06:19 UTC ( [id://219511]=note: print w/replies, xml ) Need Help??


in reply to Matching '=' and other non alphanumeric characters using regular expressions

'.' will (normally) match all characters except for the newline character.

The regular expression that you are looking for is probably:

if ($string =~ /^DEFINITION[ \t]+([^\r\n]*)/mg) {

In english, this would be: A line in $string that begins with the literal string 'DEFINITION' followed by any amount of simple white space (' ' and '\t') followed by a string of characters that do not include '\r' or '\n'. This will grab all characters to the end of the line, but not the end-of-line character sequence itself.

I choose to use [^\r\n]* instead of .* as I regularly have to ensure that my code will function equally well under both UNIX and WIN32. Using [^\r\n]* instead of .* allows me to ensure that '\r' is not picked up at the end of $1.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-03-29 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found