So, while "a" means "match lowercase a", "^a" means "do not match lowercase a". Stating a regex in terms of what you don't want to match is a bit harder. To successfully work with the Linux sed editor and the awk command in your shell scripts, you have to understand regular expressions or in short regex. However, sometimes, you might want to know where in a file the matching entries are located. In case it matters for flavors, this is going into a bash script on Debian. EDIT: Here are some strings that should match the regex You're not limited to searching for simple strings but also patterns within patterns. !999)\d{3} This example matches three digits other than 999. Any suggestions would be appreciated. Match everything except for specified strings . Regular expressions (regex) are similar to Glob Patterns, but they can only be used for pattern matching, not for filename matching. The syntax for using regular expressions to match lines in awk is: word ~ /match/ The inverse of that is not matching a pattern: word !~ /match/ If you haven't already, create the sample file from our previous article: Regular expressions are great at matching. Another handy grep trick you can use is the -o (only matching) option. Regular Expression Matching (REMATCH) Match and extract parts of a string using regular expressions. R-egular E-xpression MATCH-ing (the first many times I read the word "rematch", I just could not help my thoughts drifting back to Hulk Hogan taking on André the Giant at WrestleMania IV- those were the days...) is performed using commands on the form: With a lazy quantifier, the engine starts out by matching as few of the tokens as the quantifier allows. This operator matches the string that comes before it against the regex pattern that follows it. Unix/Linux find command “patterns” FAQ: How do I find files or directories that don’t match a specific pattern (files not matching a regex pattern, or filename pattern)?. This is a grep trick—it’s not part of the regex functionality. For instance, with A*, the engine starts out matching zero characters, since * allows the engine to match "zero or more". You could use a look-ahead assertion: (? In awk, regular expressions (regex) allow for dynamic and complex pattern definitions. The power of regular expressions comes from its use of metacharacters, which are special characters (or sequences of characters) that are used to represent something else. Since 3.0, Bash supports the =~ operator to the [[ keyword. Since there are many engines for regex, we will use the shell regex and see the bash power in working with regex. We type the following: grep -E -n 'o' geeks.txt. For instance, in a regular expression the metacharacter ^ means "not". But if you happen not to have a regular expression implementation with this feature (see Comparison of Regular Expression Flavors), you probably have to build a regular expression with the basic features on your own. (Recommended Read: Bash Scripting: Learn to use REGEX (Part 2- Intermediate)) Also Read: Important BASH tips tricks for Beginners For this tutorial, we are going to learn some of regex basics concepts & how we can use them in Bash using ‘grep’, but if you wish to use them on other languages like python or C, you can just use the regex part. A regular expression (also called a “regex” or “regexp”) is a way of describing a text string or pattern so that a program can match the pattern against arbitrary text strings, providing an extremely powerful search capability. It's easy to formulate a regex using what you want to match. One easy way to exclude text from a match is negative lookbehind: w+b(?