Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 ( [id://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?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-16 23:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found