05. Capture

Groups

Groupings are used when you want to match certain patterns, but only want to extract part of the information.

We can later reference these segments that we captured later on.

To specify a grouping, use parantheses (()).

([cat])\s\1
Matches any string in text where "c c", "a a" or "t t"

Nested groups

You can also nest capture parentheses. The captured groups are in the order in which they are defined.

Referencing

To reference the captured substrings, use a backslash (\).

\0
matches full text
\1
group 1
\2
group 2

Learn how data is stored

Data Structures and Algorithms Made Easy

Learn how data is stored Try Data Structures

A handy guide of sorts for any computer science professional, Data Structures And Algorithms Made Easy in Java: Data Structure And Algorithmic Puzzles is a solution bank for various complex problems related to data structures and algorithms. It can be used as a reference manual by those readers in the computer science industry.

$ Check price
39.9939.99Amazon 4.5 logo(339+ reviews)

More Data Structures resources

Take your Linux skills to the next level!

The Linux Command Line

Take your Linux skills to the next level! Try Linux & UNIX

The Linux Command Line takes you from your very first terminal keystrokes to writing full programs in Bash, the most popular Linux shell. Along the way you'll learn the timeless skills handed down by generations of gray-bearded, mouse-shunning gurus: file navigation, environment configuration, command chaining, pattern matching with regular expressions, and more.

$ Check price
39.9539.95Amazon 4.5 logo(274+ reviews)

More Linux & UNIX resources

Ad