I have this string for example:
str = \"my name is john#doe oh.yeh\";
the end result I am seeking is this Array:
strArr = [\'my
Assuming the result should be '&doe'
and not 'doe'
, a simple solution would be to just replace all .
and #
with &
split by spaces:
strArr = str.replace(/[.#]/g, ' &').split(/\s+/)
/\s+/
matches consecutive white spaces instead of just one.
If the result should be 'doe'
and '&.yeah'
use the same regex and add a capture:
strArr = str.replace(/([.#])/g, ' &$1').split(/\s+/)