Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: Regular Expression - delimiter/spaces problem

by demichi (Beadle)
on Feb 15, 2014 at 11:16 UTC ( [id://1075039]=note: print w/replies, xml ) Need Help??


in reply to Re: Regular Expression - delimiter/spaces problem
in thread Regular Expression - delimiter/spaces problem

Thanks a lot for your solution. I tried and it worked fine. I have questions regarding the dash_or_digit reg.

my $dash_or_digits     = qr{ (?: - | \d+ ) }msx

Why are using (?:)?

I never used this expression before and checked http://perldoc.perl.org/perlreref.html but it is not clear why use it. I tried it without and it worked also:

my $dash_or_digits     = qr{ - | \d+  }msx

Can you please let me know the reason? Thank you.

regards deMichi

Replies are listed 'Best First'.
Re^3: Regular Expression - delimiter/spaces problem
by shmem (Chancellor) on Feb 15, 2014 at 14:59 UTC
    Why are using (?:)?

    The "?:" reduces the parens effect to grouping. That means, the content of the parens will not be captured to populate a $< digit> variable ($1, $2, $3, ...). It is good practice to state exactly what is meant; and if you want to just group alternatives, then (?:) is the fitting expression.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-20 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found