use strict;
my $str = 'r22 pcd 4x108 ET 45.5 ЦО 58.5
15 /5.0j 6*108 et45 ЦО 58.5
15/ 5.0j 4x108 -45.5 58.5
pcd 4x138 15/5.0j ET58.5 ЦО45
ЦО45.5 ET58.5 19 pcd 4x 108
r15/5.6j pcd 5х112 ET60 CB66
et50 r15/5 5х112 ET60 d66
r15/5 pcd 5*112 ET60 dia 66
5.6j x 15.5 pcd 5 х 112 ет -60 CB66
5x15.5 5х112.5 ET60 CB66
250/50 r16';
my $regex = qr/# Start defining
(?(DEFINE)
(?<XSEP>\s*[xх\*\-\s]?\s*)
(?<MARGIN>(?:\.\d)?)
(?<RADIUS>r?[12]\d(?&MARGIN))
(?<J>(?:1[01]|[4-9])(?&MARGIN)j?)
(?<DIAM>
\b
(?:
(?&RADIUS)(?:\s*\/\s*(?&J))?
|
(?&J)(?&XSEP)(?&RADIUS)
)
\b
)
(?<PCD>\b(?:[pb]cd\s*)?[34568](?&XSEP)(?:98|[12]\d{2})(?&MARGIN)\b)
(?<ET>(?:(?:et|ет)\s*)?\-?\d+(?&MARGIN)\b)
(?<CB>\b(?:(?:цо|cb|d(?:ia)?)\s*)?\d{2,3}(?&MARGIN)\b)
)
# End defining
(?:
(?<diam>(?&DIAM))
|
(?<pcd>(?&PCD))
|
(?<et>(?&ET))
|
(?<cb>(?&CB))
)/ixsmup;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html