let myString = "Hello 'How are you' foo bar abc 'Strings are cool' d b s ;12gh gh76;"
const myRegEx = / \w+ "\w* +" | ;\w +; +/g // This what i have figured but its not working :(
const splitedString = myString.split(myRegEx)
console.log(splitedString)
Epected Output: ["Hello", "How are you", "foo", "bar", abc, "Strings are cool", "d", "b", "s", "12gh-gh76"]
个
让我试着解释更多:
首先,除''
或;;
内的字符串外,所有字符串均以空格""为基础拆分,如:
"Hello 'Yo what's up'"
-->;["Hello", "Yo-what's-up"]
(注意这里多了'
个,所以也要处理这个.)
然后,如果字符串在;;
内,则将其与-
联系起来(我相信这是正确的名称),如下所示:
Hello ;hi there;
-->;["Hello", "hi-there"]
并最终返回完成的所有格式化的array...不出所料.