use strict;
my $str = 'The problem:
Match lack of space following a fullstop/period. BUT! don\'t match on "i.e." and "e.g."
The current attempt above is not robust, only matches the "i" of "i.e." and "e" of "e.g." and, worse, allows all other sentences ending with "i" or "e".
Example source:
PASS: This is a test (i.e. something).Match M with no space. Don\'t match i.e.
PASS: This is a test (e.g. Something).Match M with no space. Don\'t match e.g.
PASS: This is a test (q.v. something).Match M with no space. DO match .v (not required)
PASS: This is a test.match the m.
PASS: Is this a test?Match the M.
PASS: This is a test!Match the M.
These all fail:
(?<!(i\\.e|e\\.g))[.,!?][a-zA-Z0-9]
(?<!(i\\.e\\.|e\\.g\\.))[.,!?][a-zA-Z0-9]
(?<!(i\\.e|e\\.g))(\\.|\\!|\\?)\\s+“?[a-z]
Current working copy:
(?<!(i|e))[.,!?][a-zA-Z0-9]';
my $regex = qr/(?<!(i|e))[.,!?][a-zA-Z0-9]/mp;
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