Search code examples
regexcapturing-group

Regexp capture unlimited groups


I need a little help here.

So I have string:
{block name="something" param1="param" param2="param"}
it can be:
{block name="something"} or
{block name="something" param1="value" sm="value" ng="value" um="param" .. and so on}.

What I need is to capture all possible params.

What I could figure out so far is {(?<type>[\w]+) ((?<param>[\w]+)="(?<value>[\w]+)"), but it captures only first param - "name" :/

Any help will be appreciated.


Solution

  • Here you need to use \G in-order to do continuous string match. \h matches any horizontal whitespace character.

    (?:^\{(?<type>\w+)|\G)\h*((?<param>\w+)="(?<value>\w+)")
    

    DEMO