How would I extract all alpha characters (including space) like for example:
@john camel07 st.doe!
where I only want to get john camel stdoe
.
I tried using the regex from this another SO question but it does not work.
How would I extract all alpha characters (including space) like for example:
@john camel07 st.doe!
where I only want to get john camel stdoe
.
I tried using the regex from this another SO question but it does not work.
$re = "/[^a-zA-Z ]+/";
$str = "@john camel07 st.doe!";
$subst = "";
$result = preg_replace($re, $subst, $str);
You can simply replace by empty string
all non alpha and space characters.See demo.
If your data contains unicode, this should work a bit better:
echo preg_replace("/[^[:alpha:][:space:]]/ui", '', '@john camel07 st.doe!');
Borrowed with a change from https://stackoverflow.com/a/659030/1935500