regex - A group vs. A non-capturing group
在查?:xxx時看到,擷取連結(https://coderanch.com/t/466558/java/regular-expression)中解釋如下:
A group is, by default, capturing -- meaning you can fetch groups (sub-matches inside parens) with the group(int) method.
A non-capturing group is just that -- don't capture the submatch. The group(int) method doesn't return submatches from non-capturing groups. Generally, if you don't need the value of a submatch, the group should be non-capturing, as there is no reason for the regex engine to collect the data for you, if you don't intend to use it.
A group is, by default, capturing -- meaning you can fetch groups (sub-matches inside parens) with the group(int) method.
A non-capturing group is just that -- don't capture the submatch. The group(int) method doesn't return submatches from non-capturing groups. Generally, if you don't need the value of a submatch, the group should be non-capturing, as there is no reason for the regex engine to collect the data for you, if you don't intend to use it.
留言
張貼留言