shell programming ---- Regular Expressions

Directory title


Regular Expressions

linux shell with a string of characters as the expression system to convey meaning, meta-character is used to explain the significance of the characters in the character expression, in short, it is to describe the character metacharacters character, which is used on the content of a character expression, conversion and each is described in the operation information, a regular expression is a string consisting of a string of characters and character element, the main function of the regular expression string manipulation and query text that matches a character or set of characters of text.
Here Insert Picture Description

Basic regular expressions and significance of the set of tuples deputy

symbol significance
* 0 or more before the * character that ordinary characters
. Matches any character
^ Matches the starting or end of the string of non-
$ Match end of line
[] Matching set of characters
\ Escape special meaning, shield metacharacters
<> Exact match symbol
{n} Matches the preceding character appears n times
{n,} Matches the previous character appears at least n times
{n,m} Matches the previous character appears times n ~ m
  1. "*" Symbol
      sign matches a front for 0 or more repetitions ordinary character, such as: helo hello hellllo hel are made to match o.
  2. . "" Symbol
      . Match any one character, such as ... 73. Matches abc73y, zjy73i, and. "" Symbol matches a space, x b73e
  3. "^" Character
      used to match the beginning of a line, the line represents the first character is that character back. Such as: cloud cloud match starts with its rows; 86 ^ ... * denotes three characters of the line for any character, 4 to 6 characters x86, the first seven characters can be repeated beginning 6 match, matching the characters begin to abcx86 Row.
  4. "$" Symbol
       $ symbol matching end of the line, $after the symbol on matching characters, and "^" symbol of all functions and roles opposite. Such as: micky$an expression that represents all lines match the end of micky, the match was all blank lines^$
  5. "[]" Symbol
      [] matches a set of characters, the symbol supports exhaustive method lists all the elements set of characters, but also supports the use of "-" symbol indicates a set of characters range, indicating that the set of characters ranging from "-" character to the left begins to "-" character to the right end. If you want to match any number, two methods may be used. For example: [0-9] or [0123456789], Note that [ BD] is represented by the symbol negated
  6. "\" Symbol
      "\" symbol is the escape character, special significance for shielding metacharacters, i.e. to be interpreted literally means "\" character after the symbol element. Such as:.
  7. "<>" Symbol
      as: <the> exact matching the word, the word comprising does not match the character, them, there is not so match.
  8. "{}" Symbol
      "{}" and the symbol " " is similar to symbol represents a repeated character before, however, " " symbol represents 0 or repeated any number of times, the "{}" symbol repetitions can be specified, " {} "series symbol includes three forms.
      {n} represents preceding character match occurs n times
      {n,} represents the matching character appears in front of at least n times
      {n, m} indicates the matching characters appear in front of times n ~ m
Published 106 original articles · won praise 1 · views 2338

Guess you like

Origin blog.csdn.net/weixin_43384009/article/details/104317907