\A, \b and \s are Perl for "start of string", "word boundary" and "a whitespace character", respectively. This example shows how to add a character to the beginning of each line using a sed command and bash shell. Since there are many engines for regex, we will use the shell regex and see the bash power in working with regex. Match everything except for specified strings . I tried the same thing with egrep, I tried to use it with double and single quotes, but to no better results.When I try ls /directory | grep '^[term] I get all entries beginning with term - as expected.. The annoying issue is that GNU grep (or glibc) supports some PCRE-like atoms, at least \w and \s when interpreting ERE, and in that context they very much are nonstandard. That's what I meant by the $1 . * matches everything that follows. Using awk The \K escape sequence causes what was previously matched (the first three characters) not to be included at the end, then . Regular expressions are constructed analogously to arithmetic expressions by using various operators to combine smaller expressions. The next column, "Legend", explains what the element means (or encodes) in the regex syntax. A regular expression is a pattern that describes a set of strings. Edit: I don't want to search for '^$1' but for a dynamically inserted fixed string which should only be matched if it's at the beginning of a line. You could use a look-ahead assertion: (? 5. (See the perlre man page) They're not supported in the extended regular expressions that Bash uses.. What happened is this; our first selection group captured the text abcdefghijklmno.Then, given the . Further use cases and examples of grep can found on Common Linux Text Searches. grep , expr , sed and awk are some of them.Bash also have =~ operator which is named as RE-match operator.In this tutorial we will look =~ operator and use cases.More information about regex command cna be found in the following tutorials. grep @DanielFarrell, the standard in this case is what POSIX specifies, and it doesn't know about \d.Though you're right in that PCRE are rather standard, or in the least well-defined. On each line, in the leftmost column, you will find a new element of regex syntax. The fundamental building blocks are the regular expressions that match a single character. First, we need to understand what regex is; then we will see how to use it. The -Po flags, instruct grep to interpret the pattern as a Perl-compatible regular expression. The first rule to know is that regular expression patterns are case sensitive. 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. * (any character, 0 or more times) all characters were matched - and this important; to the maximum extent - until we find the next applicable matching regular expression, if any.Then, finally, we matched any letter out of the A-Z range, and this one more times. Linux bash provides a lot of commands and features for Regular Expressions or regex. Let's create example file.txt with some text: add character at the beginning of each line Add character at the beginning of each line using sed command. ... To locate the beginning of a line in a text, use the caret character (^). When I execute ls /directory | grep '[^term]' in Bash I get a regular listing, as if the grep command is ignored somehow. In ERE, the start of string is represented as ^, and any whitespace character can be matched with [[:space:]], or if you want to just match a space, with a literal space. !999)\d{3} This example matches three digits other than 999.