Metacharacters of egrep

Metacharacters of egrep

metacharacters in use

Reading Notes

2020.09.22

👣 #regex

Summary of the egrep metacharacters1:

Metacharacter Matches
.dotMatches any one character
[. . .]character classMatches any one character listed
[^. . .]negated character classMatches any one character not listed
\charescaped characterWhen char is a metacharacter, or the escaped combination is not otherwise special, matches the literal char
   
?questionOne allowed, but it is optional
*starAny number allowed, but all are optional
+plusAt least one required; additional are optional
{min, max}specified rangeMin required, max allowed
   
^caretMatches the position at the start of the line
$dollarMatches the position at the end of the line
\<word boundaryMatches the position at the start of a word
\>word boundaryMatches the position at the end of a word
   
|alternationMatches either expression it separates
(. . .)parenthesesLimits scope of alternation, provides grouping for the quantifiers, and “captures” for backreferences
\1, \2, ...backreferenceMatches text previously matched within first, second, etc., set of parentheses

not supported by all versions of egrep

There’re three types of escaped items:

  1. The pairing of \ and a metacharacter is a metasequence to match the literal character (for example, \* matches a literal asterisk).
  2. The pairing of \ and selected non-metacharacters becomes a metasequence with an implementation-defined meaning (for example, \< often means “start of word”).
  3. The pairing of \ and any other character defaults to simply matching the charater literal (that is, the backslash is ignored).
  1. Friedl, Jeffrey E. F. Mastering Regular Expressions. 3rd ed. Sebastapol, CA: O’Reilly, 2006. 

THE END
Ads by Google

林宏

Frank Lin

Hey, there! This is Frank Lin (@flinhong), one of the 1.41 billion . This 'inDev. Journal' site holds the exploration of my quirky thoughts and random adventures through life. Hope you enjoy reading and perusing my posts.

YOU MAY ALSO LIKE

Using Liquid in Jekyll - Live with Demos

Web Notes

2016.08.20

Using Liquid in Jekyll - Live with Demos

Liquid is a simple template language that Jekyll uses to process pages for your site. With Liquid you can output complex contents without additional plugins.

Understanding Nginx location directive

Tools

2020.09.12

Understanding Nginx location directive

Location directives are essential when working with Nginx. They can be located within server blocks or other location blocks. Understanding how location directives are used to process the URI of client request can help make the request handling less unpredictable.

Setup an IKEv2 server with strongSwan

Tutorials

2020.01.09

Setup an IKEv2 server with strongSwan

IKEv2, or Internet Key Exchange v2, is a protocol that allows for direct IPSec tunnelling between networks. It is developed by Microsoft and Cisco (primarily) for mobile users, and introduced as an updated version of IKEv1 in 2005. The IKEv2 MOBIKE (Mobility and Multihoming) protocol allows the client to main secure connection despite network switches, such as when leaving a WiFi area for a mobile data area. IKEv2 works on most platforms, and natively supported on some platforms (OS X 10.11+, iOS 9.1+, and Windows 10) with no additional applications necessary.

Ads by Google