How to Split string with multiple rules in javascript

后端 未结 5 821
终归单人心
终归单人心 2021-01-25 03:18

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         


        
5条回答
  •  无人及你
    2021-01-25 03:31

    This works:

    array = string.replace(/#|\./g, ' &$&').split(' ');
    

    Take a look at demo here: http://jsfiddle.net/M6fQ7/1/

提交回复
热议问题