Capturing and non capturing group # 15

Capturing / capture group

Capture groups in regular expression are constructed by enclosing the regex pattern to be captured in parentheses.


/^(\d\d\d\d) ([-./]) (\d{1, 2}) \2 \3$/g


Matched Result

2018-09-09


Non capturing group

Non captured or non capturing group is denoted with ?: symbol. In which group the symbols are used are considered as the non captured group.


^(?:\d\d\d\d) ([-./]) (\d{1,2}) \1 \2$


Matched Result

201-09-09


Post a Comment

Previous Post Next Post