English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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

2007-12-06 07:36:44 · 3 answers · asked by am_bidar 1 in Computers & Internet Programming & Design

i tried
$p =~ /m=lr\d{2}/ )
m=lr10.moscou:te5-0
m=lr101.moscou:be5-0-0
But it is still picking the lr101
Thank you.

2007-12-06 08:09:41 · update #1

3 answers

$p =~ /(m=lr\d{2}\./)

2007-12-06 08:45:23 · answer #1 · answered by Anonymous · 0 2

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 }

2007-12-06 16:28:12 · answer #2 · answered by martinthurn 6 · 0 1

\d{2} should match exactly 2 digits.

2007-12-06 07:59:56 · answer #3 · answered by daa 7 · 0 2

fedest.com, questions and answers