下一个字符串
{ Hello, testing, hi stack overflow, how is it going }
匹配大括号内的每个单词(不带逗号)。
我尝试了这个:
\{(.*)\}
其中包含所有内容,包括逗号和方括号。
\{\w+\}
我以为这会用词,但不会,为什么?
试过这个,但是我没有用,为什么?
str = "{ Hello, testing, hi stack overflow, how is it going }";
str2 = str.match("\{(.*?)\}")[1]; // Taking the second group
console.log(str2);
console.log(str2.match("/w+"));
你试过了吗:
首先使用来获得{}之间的所有内容
\{(.*?)\}
然后在结果字符串中获取所有单词。
\w+
这里是一个解释:
\w+ matches any word character (equal to [a-zA-Z0-9_])
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句