Question:
Perl regular expression?
am_bidar
2007-12-06 12:36:44 UTC
Hello,
I am struggling with a regular expression.
I want to extract strings which have 1 or 2 digits from a list of strings.
example:
m=lr10.moscou
m=lr101.moscou
m=lr20.moscou.
I only want to dispay lr10 and lr20
I tried this regular expression
m=lr(\d\d)
but it doesnt work for me
It will be very cool if someone could advise me.
thanks
Three answers:
anonymous
2007-12-06 13:45:23 UTC
$p =~ /(m=lr\d{2}\./)
martinthurn
2007-12-06 21:28:12 UTC
You need to make sure it matches 2 digits followed by a non-digit. (and a non-digit in front of those 2 digits, too). Try this:



if ($s =~ m/\D\d\d\D/) { print $s }
daa
2007-12-06 12:59:56 UTC
\d{2} should match exactly 2 digits.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...