Test site used : https://regex101.com/
Sample text
Tag [key=AccountAlias, value=MyAccount, tagDefinition=default-tag-definition]
RegEx 0 ( Non repeating )
(\w+) \[(.*)\]
Captures
Group 1. 0-3 `Tag`
Group 2. 5-76 `key=AccountAlias, value=MyAccount, tagDefinition=default-tag-definition`
Here , group1 captures a 'type', which here is 'Tag'
RegEx 1 ( Repeating )
((\w*)=([a-zA-Z-_0-9]+))
Captures
Match 1
Full match 5-21 `key=AccountAlias`
Group 1. 5-21 `key=AccountAlias`
Group 2. 5-8 `key`
Group 3. 9-21 `AccountAlias`
Match 2
Full match 23-38 `value=MyAccount`
Group 1. 23-38 `value=MyAccount`
Group 2. 23-28 `value`
Group 3. 29-38 `MyAccount`
Match 3
Full match 40-76 `tagDefinition=default-tag-definition`
Group 1. 40-76 `tagDefinition=default-tag-definition`
Group 2. 40-53 `tagDefinition`
Group 3. 54-76 `default-tag-definition`
Here Group2 captures an attribute of a type and Group3 captures value for the attribute.
Currently I am having to apply 2 regexs. How can RegEx 0 and RegEx 1 be combined to extract both "Type" and its attributes in one go.
If my combine my regex as
/(\w+) \[((\w*)=([a-zA-Z-_0-9]+))\]/g
Nothing matches, what is going wrong. A little explanation will help ..