Reputation: 139
I have a string: "[2-0]>5&&[3-0]<21"
I would like to pull out an array of: 2-0 and 3-0
The resulting array should look like this: ["2-0", "3-0"]
Does anyone know some fancy regex that will do this, or perhaps another method?
Upvotes: 3
Views: 41324
Reputation: 67968
\[(.*?)\]
This should be your fancy regex.
See demo.
http://regex101.com/r/yZ7hR7/1
Upvotes: 2
Reputation: 174696
You could try the below code which matches the strings present inside the []
brackets,
> "[2-0]>5&&[3-0]<21".match(/[^\[\]]+(?=\])/g)
[ '2-0', '3-0' ]
Upvotes: 5