I have a code which uses a pattern and checks if a string is in the correct pattern form. if it does it say yes.
if ($port111 =~ /^(\d{1,2})\/(\d{1,2})\/(\d{1,2})$/) {print "yes port +111=$port111\n";}
allowed strings are 1/1/2 2/3/15 6/10/1 etc... all others are rejected.
I also have strings like those :
ME170-5/2/8-ME172-2/2/6-ME4028
ME172-2/1/2-ME196-1/1/3-ME4002
and i would like to extract the substring that match the
pattern .
for example :
ME170-5/2/8-ME172-2/2/6-ME4028
would extract
5/2/8 and 2/2/6
i have tried using this code but it does not work :-(.
$string = 'ME170-5/2/8-ME172-2/2/6-ME4028'; @ports = $string =~ /^(\d{1,2})\/(\d{1,2})\/(\d{1,2})$/;
can anyone point be in the right direction?
Avi
P.s also is there a way to get an array with indexed locations of where a matching patterns were found in the string?
In reply to Extract a pattern from a string by avim1968
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |