Linux regular expressions, linux Regular Expressions
POSIX standard classifies regular expressions into two types: Basic Regular Expressions> extended regular expressions. Most linux applications and tools only support basic regular expressions. =========== Basic regular expression metacharacters and their meanings =====================* matches 0 or more. match any character ^ match start with $ match end with [] match character set with \ Escape Character \ <\> exact match symbol \ {n \} match previous character appears n times \ {n, \} match the previous character to appear at least n times \ {n, m \} match the previous CHARACTER n-m times ============================== ======================================== match empty rows: ^ $ \ <\> indicates exact match symbol \ <the \> indicates matching the word, but not matching words that contain the character, such as then, them, there, another and other awk, linux tools such as perl also support regular expression extended characters ================ ===============================? Match 0 or 1 common character before it + match 1 or more common characters before it () indicates a character set or used in expr | indicates 'or ', match a set of optional characters =========================================== ====================================== the wildcard bash shell itself does not support regular expressions, shell commands and tools support wildcard characters ====================================== ======================================= * any character of any bit? Any character [] represents a combination of expressions in the range of {}. These expressions indicate the relationship between 'and' ^. Return the inverse example: ls-l *. awk. ls-l 0 ?. Pem starts with 0, followed by a character, and the suffix is. pem file ls-l [a-h] *. awk starts with [a-h. awk file ls-l [a-h] *. [^ awk] * a file starting with [a-h] With a suffix of not awk ls-l {[a-h] *. awk, 0 ?. Pem} starts with 0, followed by a character, and the suffix is. pem files or files starting with [a-h. awk file ============================================ ============================== POSIX in order to maintain the consistency of character encoding in different countries, POSIX (Portable Operating System Interface) adds special character classes, which are given in the format of [: classname]. The grep command supports POSIX character classes. ================== POSIX =================================== ================= Class Name meaning [: upper:] [A-Z] [: lower:] [a-z] [: digit:] [0-9] [: alnum:] [0-9a-zA-Z] [: space:] space or Tab [: alpha:] [a-zA-Z] [: cntrl:] ctrl key [: graph:] or [: print:] the character [: xdigit:] Between ASCII code 33-126 hexadecimal number [0-9a-fA-F] ================================== ======================================