Regex - Find All Occurrences Within a String
An essential feature on Regex - Find All Occurrences Within a String, featuring in-depth facts.
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?
2 Answers
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' ]
\[(.*?)\]
This should be your fancy regex.
See demo.