I have regex that will return value between square brackets, even if there is another set of brackets inside.
const string = 'test[number[20]] test1[20]'
const regex = /[^[\]]+\[[^[\]]+\]/g
const data = test.match(regex);
// [ "number[20]", "test1[20]] //idc about second value
And this works just fine, but I want to add that it should match only brackets that have prefix test. I am really bad with regex, could somebody explain how to achieve this, and how to make it dynamically generated, so string 'test' can be changed in regex.
Thank you for your time and patience.
Edit: Whole idea is that string might be something like this:
'number[20].isnull(12)'
Basically I will be making multiple regex, which will return multiple data, Example for upper string
RegexType returns number;
RegexValue returns 20,
RegexIsNull returns 12
But string might be just 'number' and we would be getting,
RegexType returns number,
RegexValue returns null,
RegexIsNull returns null
But it might be array as well , which can contain more declarations
'array[number[5]]'
RegexType returns array,
RegexValue returns number[5],
RegexIsNull returns null;