From the course: Bash Patterns and Regular Expressions

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Perl compatible regexes with grep

Perl compatible regexes with grep - Bash Tutorial

From the course: Bash Patterns and Regular Expressions

Perl compatible regexes with grep

- [Instructor] There are instances where POSIC's regexes don't do what we want, for instance if we want to do multiline matches or non greedy matches. Let's start with multiline matches. For multiline matches, it can be useful to use a Perl-compatible regular expression. In the chapter six directory of your exercise files, type in l s and hit enter. We're going to use the multiline dot txt file. Now type in cat space multiline dot txt and hit enter. We can see some text and then a couple of statements surrounded by curly braces, and then a comment. Let's try to match the curly braces using Grep and an ERE. Type in grep space dash o, space dash capital E, space single quote, left curly bracket, left parentheses, left square bracket, caret, right curly bracket, right square bracket, asterisk, right parentheses, right curly bracket, single quote, space multiline dot txt, and hit enter. I have specified the dash O option to only show the match. This matches the text between the curly…

Contents