I have the following regular expression that is supposed to match all words that have parenthesis around them (including the parenthesis) but it only matches one case. What am I doing wrong?
"(e), (f), and (g)".match(/\(\w+\)/)
=> #
The output should be:
=> #
Answer
Use scan()
instead. It returns an array with all the matches. match()
will only return the first match.
"(e), (f), and (g)".scan(/\(\w+\)/)
No comments:
Post a Comment