How to Split string with multiple rules in javascript

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

    use split() method. That's what you need: http://www.w3schools.com/jsref/jsref_split.asp

    Ok. i saw, you found it, i think:

    1) first use split to the whitespaces
    2) iterate through your array, split again in array members when you find # or .
    3) iterate through your array again and str.replace("#", "&#") and str.replace(".","&.") when you find

提交回复
热议问题