[英]Regex, match values inside of curly brackets
拥有下一个字符串
{ Hello, testing, hi stack overflow, how is it going }
匹配大括号内的每个单词,不带逗号。
我试过这个:
\{(.*)\}
包含所有内容,包括逗号和括号。
\{\w+\}
我认为这适用于文字,但它不会,为什么?
试过这个,但我得到了 null,为什么?
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.