Linux Regular Expression Tutorial - Grep Regex Example
Linux Regular Expression Tutorial - Grep Regex Example
Table of Content:
https://www.guru99.com/linux-regular-expressions.html 1/8
10/3/23, 8:42 AM Linux Regular Expression Tutorial: Grep Regex Example
Symbol Descriptions
https://www.guru99.com/linux-regular-expressions.html 2/8
10/3/23, 8:42 AM Linux Regular Expression Tutorial: Grep Regex Example
‘^‘ matches the start of a string. Let’s search for content that STARTS with a
Only lines that start with character are filtered. Lines which do not contain the
character ‘a’ at the start are ignored.
https://www.guru99.com/linux-regular-expressions.html 3/8
10/3/23, 8:42 AM Linux Regular Expression Tutorial: Grep Regex Example
Expression Description
Matches the preceding character appearing ‘n’ times but not more
{n,m}
than m
Example:
We want to check that the character ‘p’ appears exactly 2 times in a string one after
the other. For this the syntax would be:
https://www.guru99.com/linux-regular-expressions.html 4/8
10/3/23, 8:42 AM Linux Regular Expression Tutorial: Grep Regex Example
Expression Description
Example:
Suppose we want to filter out lines where character ‘a’ precedes character ‘t’
Brace expansion
The syntax for brace expansion is either a sequence or a comma separated list of
items inside curly braces “{}”. The starting and ending items in a sequence are
separated by two periods “..”.
Some examples:
https://www.guru99.com/linux-regular-expressions.html 5/8
10/3/23, 8:42 AM Linux Regular Expression Tutorial: Grep Regex Example
In the above examples, the echo command creates strings using the brace
expansion.
Summary:
Regular expressions are a set of characters used to check patterns in strings
They are also called ‘regexp’ and ‘regex’
It is important to learn regular expressions for writing scripts
Some basic regular expressions are:
Symbol Descriptions
Expression Description
https://www.guru99.com/linux-regular-expressions.html 6/8
10/3/23, 8:42 AM Linux Regular Expression Tutorial: Grep Regex Example
Expression Description
Matches the preceding character appearing ‘n’ times but not more
{n,m}
than m
AD
Wireless Keyboard and Mouse Set, 2.4 GHz Wireless USB Keyboard and Mouse
Combo with USB recevier, Slim Ergonomic Keyboard for Windows, Computer, P…
443
28% off Deal
£ 16.61 £22.99
https://www.guru99.com/linux-regular-expressions.html 7/8
10/3/23, 8:42 AM Linux Regular Expression Tutorial: Grep Regex Example
About
About Us
Advertise with Us
Write For Us
Contact Us
Career Suggestion
SAP Career Suggestion Tool
Software Testing as a Career
Interesting
eBook
Blog
Quiz
SAP eBook
Execute online
Execute Java Online
Execute Javascript
Execute HTML
Execute Python
https://www.guru99.com/linux-regular-expressions.html 8/8