php - Regex for a period not immediatly following a word in a list, without variable length lookbehind? -
i'm trying write regex matches periods not followiing word list.
i believe need lookahead or lookbehind assertion this, , i've tried:
/(?!(mr|ms|mrs))\./u
, /(?!(mr|ms|mrs)\.)\./u
these both matches all periods it's not excluding periods after words.
i tried lookbehind, believe need:
/(?<!(mr|ms|mrs))\./u
but looks have fixed length because won't compile: preg_replace(): compilation failed: lookbehind assertion not fixed length @ offset 15
.
here's few test cases, , expected result when using preg replace remove matches:
'mr. tom a. suggins' // mr. tom suggins 'mrs.. jane p suggins, jr.' // mrs. jane p suggins, jr '.ms.. .jane p. suggins' // ms. jane p suggins
is there way in php without variable length lookbehind support?
you can use (*skip)(*f)
verbs in pcre regex fail/skip selected matches;
$repl = preg_replace('/(?:mrs?|ms)\.(*skip)(*f)|\./', '', $str);
Comments
Post a Comment