I have a string like this: "hello %{name} good %{middle} bye"
.
I’m trying to find an effective way to extract out the values in-between the braces, so ideally I would end up with an array of ["name", "middle"]
.
Using match
I can almost get there. The following returns: ['%{name}', '%{middle}']
:
"hello %{name} good %{middle} bye".match(/%{([w]+)}/g)
I’m not sure why it’s including the %
, {
, and }
characters in the return though.
How can I adjust my regular expression to only match name
and middle
?