Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Regex to match 20 chars of some digits followed by some spaces

by ysth (Canon)
on Dec 19, 2003 at 06:19 UTC ( [id://315752]=note: print w/replies, xml ) Need Help??


in reply to Regex to match 20 chars of some digits followed by some spaces

/\d(?!.{0,18} \d)[\d ]{19}/
Matches 20 digits and spaces, beginning with a digit, where there are no digits following spaces.

Update: had 0,19, meant 19

  • Comment on Re: Regex to match 20 chars of some digits followed by some spaces
  • Download Code

Replies are listed 'Best First'.
Re:^2 Regex to match 20 chars of some digits followed by some spaces
by Roy Johnson (Monsignor) on Dec 19, 2003 at 20:17 UTC
    Excellent. Piqued my interest in this approach, which led to a few observations:
    • you probably want to anchor your match
    • you could have used dot-star instead of .{0,18}, or you could have specified the chars for the dot (TIMTOWTDI) -- probably the most efficient thing would be to specify (?!\d* +\d), which made me realize...
    • it can be done with a positive lookahead like so: /^\d(?=\d* *$)[\d ]{19}$/ ("leading digit, followed by digits, then spaces, then end of string, etc.")

    The PerlMonk tr/// Advocate
      I actually have never used Parse::RecDescent but was assuming it was working on an input buffer using the supplied regex as something like /\G$regex/gc so I didn't supply a beginning anchor and an ending anchor is not usable. I haven't got around to checking my assumption yet...and you know what they say when you assUme.
        Well, I've read through Parse::RecDescent and it does work as I had guessed. So solutions to this problem should not have ^ and may not depend on $.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2025-01-25 05:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (70 votes). Check out past polls.