From the course: Cert Prep: LPIC-1 Exam 101 (Version 5.0)

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Alternation and grouping with regexes

Alternation and grouping with regexes - Linux Tutorial

From the course: Cert Prep: LPIC-1 Exam 101 (Version 5.0)

Start my 1-month free trial

Alternation and grouping with regexes

- [Instructor] Alternation allows us to specify one thing or another. Grouping allows combining patterns into one match. This is important because we can use alternation to match one or another group, or we can use a occurrence operands to specify how many times we should match the entire group. This might not seem like it's that important, but using alternation expression groups and specifying occurrences can be quite powerful. Let's start with the basic example. To specify dog or cat separate them with a pipe symbol. This would match both dog and cat or even multiple occurrences of both if we didn't specify an anchor or occurrence operands due to concatenation and greedy matches. However, this syntax is the foundation of alternation. We want to specify the number of occurrences. We place the regex inside of a parenthesis and then specify an occurrence operand. For instance, if you wanted to match zero or one dog or cat,…

Contents