Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Regular Expression: search two times for the same number of any signs

by Ratazong (Monsignor)
on Nov 29, 2016 at 10:17 UTC ( #1176779=note: print w/replies, xml ) Need Help??


in reply to Regular Expression: search two times for the same number of any signs

Hi

I would recommend to create the regular expression dynamically, based on the length of the input-string (or on the last "x"). It could somehow look like this:

my $s = "x12345x23x56x"; my $len = (length($s)-3)/2; my $re = "x" . "."x$len . "x" . "."x$len . "x"; # this is the RegEx +you want if ($s =~ /$re/) { print "ok\n"; } else {print "nok\n";}

HTH, Rata

  • Comment on Re: Regular Expression: search two times for the same number of any signs
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2023-03-21 18:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (60 votes). Check out past polls.

    Notices?