Part of the problem is lookahead matching -- I want to match the whole string if it meets these criteria rather than the first part of the string that doesn't match. Since 3.0, Bash supports the =~ operator to the [[ keyword. 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. Regular Expression Matching (REMATCH) Match and extract parts of a string using regular expressions. However, sometimes, you might want to know where in a file the matching entries are located. We type the following: grep -E -n 'o' geeks.txt. Any suggestions would be appreciated. This operator matches the string that comes before it against the regex pattern that follows it. Since there are many engines for regex, we will use the shell regex and see the bash power in working with regex. With a lazy quantifier, the engine starts out by matching as few of the tokens as the quantifier allows. Stating a regex in terms of what you don't want to match is a bit harder. 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: EDIT: Here are some strings that should match the regex !999)\d{3} This example matches three digits other than 999. 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: You're not limited to searching for simple strings but also patterns within patterns. In case it matters for flavors, this is going into a bash script on Debian. 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)?. Regular expressions are great at matching. 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. So, while "a" means "match lowercase a", "^a" means "do not match lowercase a". It's easy to formulate a regex using what you want to match. (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. You could use a look-ahead assertion: (? Match everything except for specified strings . Another handy grep trick you can use is the -o (only matching) option. 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. Regular expressions (regex) are similar to Glob Patterns, but they can only be used for pattern matching, not for filename matching. This is a grep trick—it’s not part of the regex functionality. For instance, in a regular expression the metacharacter ^ means "not". 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. One easy way to exclude text from a match is negative lookbehind: w+b(?