I have JS file and I need to parse that array in it:
something: ['Prefix.All','Ignore.Me','Prefix.Another']
I need to get all elements from “something” array with defined prefix.
Now I can get it, if array will contain only one element. My regexp:
String: something: ['Prefix.All']
Can get element with:
/something\s*:\s*\[['"](Prefix[a-zA-Z0-9.]+)['"]]/
But how to find many elements in array? And how to find more than one “something” array in file?
In PHP you need to do it in two steps (which is probably better anyway – cramming everything into a single regex isn’t always the best idea).
First, match the array you’re looking for. Note that this regex requires that there are no brackets between the delimiters
[and], so nested arrays or strings that contain brackets will cause the regex to fail (as in “match the wrong text”):This will find the first occurrence of a string like
something: ['Prefix.All','Ignore.Me','Prefix.Another']and put'Prefix.All','Ignore.Me','Prefix.Another'into$result.Then you can get all the matches from that: