My snippet reads the lines of text from the <DATA> filehandle. You didn't mention where the strings are coming from, so you'll have to adjust accordingly. The regexp needs to be free to match anywhere in the string, so the ^ and $ anchors were hurting you.
my $re = qr{ ( (?: \d{1,2}/ ){2} \d{1,2} ) }x; while( my $line = <DATA> ) { while( $line =~ m/ $re /gx ) { print "Line: $.\t Column: ", $-[0], "\tMatched: $1\n"; } } __DATA__ ME170-5/2/8-ME172-2/2/6-ME4028 ME172-2/1/2-ME196-1/1/3-ME4002
It's up to you to decide what information you would like to push onto an array. Perhaps instead of the print, you could use, push @array, [ $., $-[0], $1 ];
There are a lot of funny looking variables there: $. tells you the line number most recently read from a file. $-[0] tells you the match position of $1. And $1 holds what matched inside the first set of capturing parens within the regular expression.
Dave
In reply to Re: Extract a pattern from a string
by davido
in thread Extract a pattern from a string
by avim1968
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |