Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Regex Matching Query

by ww (Bishop)
on Mar 26, 2013 at 15:02 UTC ( #1025540=note: print w/ replies, xml ) Need Help??


in reply to Re: Regex Matching Query
in thread Regex Matching Query

Unfortunately, the code in the direct parent (and similar offerings above) does not produce what I understand to be OP's intended result. Execution of the code in Re: Regex Matching Query goes like this:

C:\> 1025454.pl Show name: TEST SHOW S Show rest: 01E01
It's my understanding that all after the final space -- i.e., S01E01 -- is the desired output.

So why is the regex a few degrees off plumb? As written the technical greediness of the death star in the first capture is mitigated by the trailing questionmark... but the second capture looks for a digit as its starting point, relegating the "S" to the first capture.

Consider instead the elevated particularity of:

if(my ($show, $file) = $file =~ /(.*?)\s([A-Z]\d+.*)/) { print "Show name: $show\n"; print "Show rest: $file\n"; }
which outputs:
Show name: TEST SHOW Show rest: S01E01
Regexen entirely capable of biting BOTH an excess and an insufficiency of precision in their crafting.

If you didn't program your executable by toggling in binary, it wasn't really programming!


Comment on Re^2: Regex Matching Query
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (14)
As of 2014-07-30 08:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls