Having the next string
{ Hello, testing, hi stack overflow, how is it going }
Match every word inside of curly brackets without the comma.
I tried this:
{(.*)}
which take all, commas and brackets included.
{w+}
I thought this will work for words but it wont, why?
Updated
Tried this but I got null, why?
JavaScript
x
5
1
str = "{ Hello, testing, hi stack overflow, how is it going }";
2
str2 = str.match("{(.*?)}")[1]; // Taking the second group
3
console.log(str2);
4
console.log(str2.match("/w+"));
5
Advertisement
Answer
did you try:
first get everything between {} by using
JavaScript
1
2
1
{(.*?)}
2
then get all words inside of the resulting string.
JavaScript
1
2
1
w+
2
Here is an explanation:
JavaScript
1
3
1
w+ matches any word character (equal to [a-zA-Z0-9_])
2
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed
3