How to Split string with multiple rules in javascript

后端 未结 5 865
终归单人心
终归单人心 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:36

    I would think a combination of split() and replace() is what you are looking for:

    str = "my name is john#doe oh.yeh";
    
    strArr = str.replace('\W',' &');
    
    strArr = strArr.split(' '); 
    

    That should be close to what you asked for.

提交回复
热议问题