Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Space or end of string in regex

by davies (Vicar)
on Feb 02, 2012 at 23:00 UTC ( #951550=note: print w/ replies, xml ) Need Help??


in reply to Re: Space or end of string in regex
in thread Space or end of string in regex

This works perfectly, thank you. I'm not worried about multiple spaces as a single space is enough to indicate that this is a keyword that needs special treatment and multiple spaces are handled in that routine. My problem was not realising that I needed to anchor at the start. I was therefore looking for a character class that contained space or end of string and therefore, once again, flailing at demons.

Am I right in thinking that replacing the slashes with square brackets is optional?

Regards,

John Davies


Comment on Re^2: Space or end of string in regex
Re^3: Space or end of string in regex
by BrowserUk (Pope) on Feb 02, 2012 at 23:15 UTC
    Am I right in thinking that replacing the slashes with square brackets is optional?

    Indeed. Purely personal preference.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Re^3: Space or end of string in regex
by Marshall (Prior) on Feb 03, 2012 at 20:47 UTC
    if( $line =~ m[^REM $sTest\s*$]i ) {
    If you use the //, then you don't need the "m" in front, but otherwise its just style preference.

    There is one other fine point about this, if $sTest could contain some characters that would normally mean something to the regex engine, like a "(" or whatever, you can specify to interpret the string $sTest literally - meaning ignore the meaning of those characters. This is done by surrounding $sTest with a \Q \E pair.

    if( $line =~ /^REM \Q$sTest\E\s*$/i ) {

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-09-01 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (13 votes), past polls