Reputation: 3393
I have a string:
var string = "116 b (407) (90 A / 122 M) (11.2004)"
In that string I want to match specific parenthesis ()
and its context (i.e. (90 A / 122 M)
) including specific character /
.
I tried:
string.match(/\([/]\)/g)
But that returns null
. What am I doing wrong?
Best Regards
Upvotes: 2
Views: 63
Reputation: 114
you can try string.match(/\([^)]*\)/g)
which may give what you want:
["(407)", "(90 A / 122 M)", "(11.2004)"]
Upvotes: 0
Reputation: 626699
Your \([/]\)
pattern matches a (
, followed with /
, followed with )
, a 3-char sequence.
You may use
/\([^()]*\/[^()]*\)/g
See this regex demo
Details:
\(
- opening (
parenthesis[^()]*
- zero or more chars other than (
and )
(a \/
can be added at the end to improve performance a bit: [^()\/]*
)\/
- a /
symbol[^()]*
- zero or more chars other than (
and )
\)
- closing parenthesisUpvotes: 4