I would like to check if the preceding character of a search pattern
is an alphanumeric character.
If true, do nothing.
If fasle, remove the preceding space
in the search pattern
.
For example:
$string1 = "This is a test XYZ something else";
$string2 = "This is a test? XYZ something else";
$pattern = " XYZ";
In $string1 scenario, the preceding character of the search pattern is t
and considered a match, nothing will be perform.
In $string2 scenario, the preceding character of the search pattern is ?
and considered a non-match, and I'm removing the extra space in searhc pattern
.
Making it:
$string2 = "This is a test?XYZ something else";
How can this be accomplished in PHP?