I've been Googling this regex behavior all afternoon.
$str = ' b c d w i e f g h this string';
echo preg_replace('/\s[bcdefghjklmnopqrstuvwxyzBCDEFGHJKLMNOPQRSTUVWXYZ]{1}\s/', ' ', $str);
I want to remove all instances of a single character by itself (except for A and I) and leave one space in its place. This code appears to work on every other match. I suspect this is because the matches overlap each other.
I suspect a lookaround would be appropriate here, but I've never used them before and could use a snippet.
EDIT: Just to avoid confusion about what I am trying to accomplish. I want to turn the above string into this:
$str = ' i this string';
Notice all single-letter characters that are NOT "A" or "I" have been removed.