my $str='expire=0';
if ($str =~/expire\s*=\s* (?: 0[1-9]|[1-9][0-9])/){
print " found it ";
}
its not working
Condition expire=
should be followed by a number between 1-99
?
If you want to use spaces in your regex without them actually matching spaces, you need to use the x
modifier on your regex. I.e. / foo /x
matches the string "foo", while / foo /
only matches " foo ".
Your regex has spaces, remove them:
/expire\s*=\s* (?: 0[1-9]|[1-9][0-9])/
^ ^
Also the regex 0[1-9]|[1-9][0-9]
does not match 0
.
EDIT:
Based on your comments, you want to allow a number from 1-99
after expire=
so you can use:
/^expire\s*=\s*(?:[1-9]|[1-9][0-9])$/
or a shorter version:
/^expire\s*=\s*(?:[1-9][0-9]?)$/
Since your example has 0
after expire=
it'll not be matched.
Also note that I've added the start and end anchors. Without them the regex may match any valid sub-string of the input. Example it can match expire=99
in the input expire=999
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With