I have a string like that: obj[attr1=val1 attr2=val2 attr3=val3]
i need to extract object name and attributes.
Earlier, i've decided similar task in javascript using next regexp:
/^(\w+)(?:\[(\w+=\w+)(?:\s(\w+=\w+))*\])?$/
Now i have a trouble deciding in java:
Pattern pathPattern = Pattern.compile("^(\\w+)(?:\\[(\\w+=\\w+)(?:\\s+(\\w+=\\w+))*\\])?$");
I'm getting just a object name and first attribute. It seems that Mather class gets group count corresponding to count of "()" without considering symbol "*".
Is exists the possibility to make working java reg exp like js regexp, or i need to make two steps extraction?
thank you
*. But just one group count.*, the pattern will be continuously replaced by the next match. Hence at last you would have only one matching string. That's why its only one group.