The regular expression of shell programming

Source: Internet
Author: User

Regular expressions are primarily a grammar rule used to describe character permutations and matching patterns. It is mainly used for the pattern segmentation, matching, finding and substitution of strings, the main purpose is to match.

Wildcard characters:

*-Match any Content

? -Match any one character

[]-matches the contents in parentheses

A regular expression is used to match a string in a file that matches a condition, and is to contain a match .

Wildcards are used to match the qualified file names, which are exact matches .

grep, awk, sed, and other commands can support regular expressions.

Commands such as LS, find, and CP do not support regular expressions, so they can only be matched using the shell's own wildcard character.

The general matching form is listed as follows:

* previous character matches 0 or more times
. match any character except newline characters
^ Match header
$ matches end of line
[] matches any one of the characters in the brackets, which can be listed as long as one character is satisfied
[^] matches any character except for the brackets
\ escape character
\{n\} indicates that the characters that precede them appear exactly n times, preferably preceded or preceded by a qualifying character, which makes it difficult to match exactly.
\{n,\} indicates that the preceding characters appear no less than n times, in fact the last match is almost the same as this
\{n,m\} indicates that the characters preceding it appear not less than n times, not more than m times.
   

Regular expression in the beginning of a language will be more trouble, so more hands-on operation to better familiar.

The regular expression of shell programming

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.