Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: validate variable-length lines in one regex?

by BrowserUk (Patriarch)
on Jul 06, 2015 at 18:23 UTC ( [id://1133412]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    $s = 'a1 1 2 1.0 1.1 1.2 1.3';;
    print grep defined, $s =~ m[([a-z]\d)\s+(\d)\s+(\d)(?:\s+(\d\.\d))?(?:
    +\s+(\d\.\d))?(?:\s+(\d\.\d))?(?:\s+(\d\.\d))?(?:\s+(\d\.\d))?(?:\s+(\
    +d\.\d))?(?:\s+(\d\.\d))?(?:\s+(\d\.\d))?];;
    ...
    $s = 'a1 1 2 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7';;
    print grep defined, $s =~ m[([a-z]\d)\s+(\d)\s+(\d)(?:\s+(\d\.\d))?(?:
    +\s+(\d\.\d))?(?:\s+(\d\.\d))?(?:\s+(\d\.\d))?(?:\s+(\d\.\d))?(?:\s+(\
    +d\.\d))?(?:\s+(\d\.\d))?(?:\s+(\d\.\d))?];;
    a1 1 2 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7
    
  2. or download this
    $re = '([a-z]\d)\s+(\d)\s+(\d)' . join '', '(?:\s+(\d\.\d))?' x 10;;
    $re = qr"$re";;
    ...
    $s = 'a1 1 2 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7';;
    print grep defined, $s =~ $re;;
    a1 1 2 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-28 16:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found