0

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?

    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+"));
Sharki
  • 404
  • 4
  • 23
  • 1
    Does this answer your question? [Reference - What does this regex mean?](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – iBug Dec 07 '20 at 04:45

1 Answers1

1

did you try:

first get everything between {} by using

\{(.*?)\}

then get all words inside of the resulting string.

\w+

Here is an explanation:

\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
ha-neul
  • 3,058
  • 9
  • 24
  • it gets all words but not only those ones who are inside of curly brackets – Sharki Dec 07 '20 at 04:45
  • I think that you're so right also it makes sense but for some reason I got null, pretty sure that it's me doing the things wrong, so I'm gonna update the post with the code! – Sharki Dec 07 '20 at 05:02
  • Nevermind, I just realize I was doing `/w+` instead of `\w+`, thanks! – Sharki Dec 07 '20 at 05:07