When constructing a regular expression, you may need to reference some previously matched regex term. To do so, we may use backreferences.
The phrases that you want to reference are to be enclosed with parentheses (\(...\)). To reference it, use \digit, where \1 represents the first referenced phrase, \2, the second, and so on.
For example, a regex such as \(foo\)ber\(buzz\)*\2\1 simplifies to (foo)ber(buzz)*buzzfoo. Since the asterisk can have zero or many elements of the previous regex, this would match an text such as fooberbuzzbuzzfoo, fooberbuzzbuzzbuzzfoo, and so on.
So far we have learned how to use regex to search within lines, with no restrictions. Thus we can use zip to find elements that have the text 'zip' anywhere within its text. This is great, but what if we want to search strings that start or end with specific letters? To do precisely this, we use the
$ ls /usr/bin/ | grep '^zip' # files that start with zip
zip zipcloak zipdetails zipdetails5.16 zipdetails5.18 zipgrep zipinfo zipnote zipsplit
# files that end with zip $ ls /usr/bin | grep 'zip$'
funzip gunzip gzip unzip zip
# files that start and end with zip $ ls /usr/bin | grep '^zip$'
The ^$ matches empty strings or lines, and may be used as grep -v ^$ to filter out all empty lines.
In BRE, when ^ or $ are used anywhere else beside the beginning or end of the line, it has no effect, so it turns back into a literal character. For example, [ab^cd] means the letters a, b, ^, c, or d.
The ^ is used to signify that some characters begins with some regex. However, remember that if it appears as the first element in brackets, it'll change its meaning to negation.
Thus, we [^abcd] is different from ^[abcd]. The first matches any character not including a, b, c, or d. The second searches for text that starts with a, b, c, or d.
Stretch out your back and relieve your back muscles with inversion therapy. This device counteracts the forces of gravity on the body by decompressing and elongating the spine. By using this product just ten minutes a day, you can be well on your way to improved circulation and posture while relieving muscle aches, back pain and stress.$$ Check price
This book approaches system administration in a practical way and is an invaluable reference for both new administrators and experienced professionals. It details best practices for every facet of system administration, including storage management, network design and administration, email, web hosting, scripting, and much more.$ Check price