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
Node Status?
node history
Node Type: note [id://1176779]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2018-07-16 07:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (333 votes). Check out past polls.

    Notices?