From the course: Bash Patterns and Regular Expressions
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Back references and subexpressions - Bash Tutorial
From the course: Bash Patterns and Regular Expressions
Back references and subexpressions
- [Instructor] I've mentioned before that in GNU tools, BREs and EREs are equal. It's interesting to note that in the POSIX Standard, EREs do not support backreferences. If you're using POSIX tools, you need to convert these to BREs to get them to work. A backreference is a pattern that's stored in a buffer to be recalled later. We can remember up to nine patterns which is the limit. For instance, if we wanted to match words that had more than one pair of ss, we'd first create our pattern of double ss and place it in parentheses so it's remembered. And lastly, we'd recall the pattern using a backreference. The format is \1, \2 and so on up to \9. Note that this regular expression matches with double ss in the parentheses and then matches again with the backreference. This regular expression would match double ss followed by any number of characters and then more double ss. We can recall the pattern more than once as well. For instance, let's recall our double ss pattern more than…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
What are regular expressions?2m 35s
-
(Locked)
Why aren't regexes consistent?1m 30s
-
(Locked)
Basic vs. Extended Regular Expressions3m 38s
-
(Locked)
Regex support in command line tools57s
-
(Locked)
Matching characters and words3m 21s
-
(Locked)
Specifying occurrences1m 56s
-
(Locked)
Alternation and grouping3m 21s
-
(Locked)
Back references and subexpressions1m 48s
-
(Locked)
-
-
-
-
-