in reply to ambiguous regex match
#!/usr/bin/perl use warnings; use strict; my @data; while (<DATA>) { next if ( /^\s*$/ ); #skip blank lines # easy way to to get numbers after "=" my ($tag1, $tag2, $extra) = /\s*=\s*(\d+)/g; #skip malformed lines.. #must be 2 number tokens after "=" if (defined $tag1 and defined $tag2 and not defined $extra) { print "$tag1 \t$tag2\n"; } else { print "Bad Line:$_"; } } =prints 12345 99999 Bad Line:blabla;tag1=12345;blabla Bad Line:awdrfaf; tag2 = 122345; 6768 9876 Bad Line:079a8; tag1 =345; tag2 = 895; tag3=3987; 12567 98999 7899 8977 =cut __DATA__ blabla;tag1=12345;blabla;tag2=99999 blabla;tag1=12345;blabla awdrfaf; tag2 = 122345; asdf;tag 1 = 6768; tag2= 9876; 079a8; tag1 =345; tag2 = 895; tag3=3987; blabla;tag1 =12567;blabla;tag2= 98999 blabla;tag1= 7899;blabla; tag2 =8977
|
|---|