How to use regular expressions in Linux

Source: Internet
Author: User

First, regular expressions

In computer science, regular expressions are used to describe or match a series of strings that conform to a certain syntactic rule; in a text editor or some tool (such as bash environment), regular expressions are often used to retrieve text content that conforms to a pattern. In Linux, regular expressions are patterns written by a class of characters. Filter the strings needed in the bash environment by implementing well-defined patterns.

A regular expression is made up of a series of ordinary characters and some meta characters. Ordinary characters mainly include uppercase and lowercase letters and numbers. Metacharacters has a special meaning. It does not represent the meaning of the character itself and is used for additional functional descriptions. Regular expressions have basic regular expressions and extended regular expressions, and I'll list some common metacharacters that are commonly used in Linux, and explain them with relevant examples:

1. Basic Regular Expressions

2. Extending Regular Expressions

The following main lists the partial metacharacters different from the basic regular expressions

3. There are some other escape characters in Linux, but there are only a few enumerated and explained in common. Interested friends can view the help system provided in the man document through the man 7 regex.

Ii. Use of GREP commands

Let me show you how to use the grep command to do pattern matching using regular expressions. Let me first introduce the basic use of GREP commands.

grep (Global search Regular Expression and Printing), which represents a comprehensive search of regular expressions and prints, is a powerful text search tool that can use regular expressions to search for text and print matching rows. grep has three kinds, including grep, Egrep, and Fgrep.

The following are indicated respectively:

This paper url:http://www.bianceng.cn/os/linux/201410/45620.htm

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.