skip to content
Alvin Lucillo

Capture subgroup

/ 1 min read

💻 Tech

To extract information from text with combination of capture groups in the form of subgroups, you use inner capture groups.

Regex: ([A-Za-z]+ (\d+)) This searches for a line with one or more alphabetic characters followed by a space and one or more numbers. The outer capture group captures the month and year with year in a capture subgroup.

Jan 1987  -- captures 'Jan 1987' and '1987'
May 1969  -- captures 'May 1969' and '1969'
Aug 2011  -- captures 'Aug 2011' and '2011'