我有一個看起來像這樣的正則表達式:[@|#](.*?)\s我基本上想要的是,將匹配的正則表達式拆分為數組。所以我使用以下代碼:var testString = "Hi this is a test @[email protected] and @martin we have to go."
console.log(testString.split(/(\@|\#)(.*?)\s/));我得到的結果是這樣的:["Hi this is a test ", "@", "[email protected]", "and ", "@", "martin", "we have to go."]我真正想要的是:["Hi this is a test ", "@[email protected]", "and ", "@martin", "we have to go."]https://regex101.com/r/yJf9gU/1https://jsfiddle.net/xy4bgtmn/
正則表達式只得到完全匹配(不分組)
嚕嚕噠
2023-06-15 09:28:21