Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Shell Programming Regular Expressions     - PostgreSQL-XL installation and deployment (Database)

- PL / SQL -> UTL_FILE use presentation package (Database)

- RHEL5.x RHEL6.x replace CentOS yum source (Linux)

- MyCAT read and write separation of MySQL (Database)

- SME Linux network security policy server security (Linux)

- Using Java program determines whether it is a leap year (Programming)

- Depth understanding of JavaScript new mechanism (Programming)

- Fedora 22 install Adobe Flash Player (Linux)

- Ubuntu amend resolv.conf restart failure problem (Linux)

- Java garbage collection and heap memory layout (Programming)

- Android Application Development: Genymotion can not start solving (Linux)

- Windows Server 2012 R2 Datacenter install SQL Server 2016 CTP (Database)

- Fedora 22 Server how to upgrade to Fedora 23 Beta Server (Linux)

- Achieve single backup of MySQL by innobackupex (Database)

- Install the free open source financial software GnuCash 2.6.6 under Ubuntu (Linux)

- Linux installed and tested the deployment of Kafka distributed cluster (Server)

- Linux package management (Linux)

- Ubuntu Series Installation Docker (Linux)

- Linux common network tools: Scan routing of mtr (Linux)

- CentOS7 installation hardware monitoring for Zabbix enterprise applications (Server)

  Shell Programming Regular Expressions
  Add Date : 2018-11-21      
  What are regular expressions? Regular expressions are syntax rules used to describe the character arrangement and the matching pattern. In many programming languages support the use of regular expressions for string manipulation, in different languages of regular expressions is slightly different, but after all, regular, its essential idea is the same, when we have the shell regular, go and python or perl inside positive expression, you will find it is really the same stuff.

In some command shell, some do not support regular expressions, but they support Linux inside the wildcard is the wildcard is what stuff it, it is with regular expressions what is the relationship?

Regular expressions for qualified string matching in the file, that contains a regular match. grep, awk, sed, etc. commands support regular expressions. Wildcard to match qualified filename, wildcards are an exact match. ls, find, cp These commands do not support regular expressions, we can only use their own shell wildcard to match.

Wildcards are mainly the following three:

* Matches any character
? Matches any one content
[] Matches a character in brackets

First, the regular expression is used in this document Chinese string matching, and wildcards are used to match qualified filename; secondly contains a matching regular expression is, as long as a regular string that contains just match, but the wildcard is exact, that is, we will have to match exactly with the criteria string.

Having said that, in fact, a regular expression is mainly used for string pattern segmentation, matching, find and replace operation, let's look at the basic regular expression metacharacters and its role.

Metacharacters effect illustration
* Match the previous character 0 times or as many times as "a *" matches everything, including blank lines
"Aa *" matches containing at least one of a row
"Aaa *" matches the last two consecutive contain a string
"Aaaaa *" contain a minimum of four consecutive matches a string
. Matches any character except a newline
"S..d" s and d match between these two letters must have two

Word character
"S. * D" match between s and d alphabetic characters arbitrary
. "*" Matches everything

^ Matches the beginning of the line "^ hello" hello to match the beginning of the line
"^ M" matching rows in uppercase "M" at the beginning of
$ Matches the end of the line "hello $" matches the end of the line hello
"N $" matches lowercase "n" at the end of the line
"^ $" Matches blank lines
[] Matches any one character in brackets specified, only matching a
"[Aeiou]" matches any vowel,
"[0-9]" matches any digit,
"[A-z] [0-9]" matches lowercase letters and one digit constituted

Two characters.
"S [ao] id" s match and i letters, either a, or is o

"[0-9]" matches any number

"^ [A-z]" matches begin with a lowercase letter row

[^] Matches any character other than the brackets of a character "[^ 0-9]" matches any one non-numeric characters,
"[^ A-z]" represents any one non-lowercase
"^ [^ A-z]" matches the beginning of the line is not a lowercase letter
"^ [^ A-zA-Z]" does not begin to match letters row
\ Escape character. The meaning of the symbols for special cancellation "\. $" Matches the "." At the end of the line
\ {N \} indicate that the previous character appears exactly n times "[0-9] \ {4 \}" matches four numbers,
"[1] [3-8] [0-9] \ {9 \}" matches the phone number
"A \ {3 \}" matches a string of three consecutive letters appear
"[0-9] \ {3 \}" matches contain consecutive three-digit string
\ {N, \} indicate that the previous character appears no less than n times
"[0-9] \ {2 \}" represents two or more numbers.
"[0-9] \ {3, \} [a-z]" matches with a minimum of three consecutive numbers beginning


\ {N, m \} indicate that the previous character appears at least n times, most appear
m times
"[A-z] \ {6,8 \}" matches 6-8 lowercase letters.
"Sa \ {1,3 \} i" matches the letter s and i immediately at least one a,

A maximum of three

Here are a few simple Liezi:

(1) to match the date format YYYY-MM-DD "[0-9] \ {4 \} - [0-9] \ {2 \} - [0-9] \ {2 \}"
(2) match the IP address XXX.XXX.XXX "[0-9] \ {1,3 \} \. [0-9] \ {1,3 \} \. [0-9] \ {1,3 \} "

(3) matching Tencent QQ number "[1-9] [0-9] \ {4,9 \}"
- Learning C ++ Standard Template Library and data structures (Programming)
- Virt Related Command Summary (Linux)
- build Android environment on Ubuntu 12.04 (Server)
- Linux kernel RCU (Read Copy Update) lock Brief - prequel (Linux)
- Linux Getting Started tutorial: 3D effects and beautify your desktop (Linux)
- How SSHfs mount a remote file system on Linux (Linux)
- Build a super simple "hardware" firewall router (Linux)
- SVN common commands (Linux)
- Open log in Hibernate (Programming)
- CentOS7 virtual machine starts appear Permission denied (Linux)
- XP virtual machine under VirtualBox solve occupy 100% CPU problem (Linux)
- Thunderbird 24.4.2 has been released for use with PPA updates (Linux)
- C language print various graphic (Programming)
- CentOS iptables firewall configuration (Linux)
- Android View event delivery (Programming)
- Java memory area and memory overflow exception (Programming)
- 11 examples in Linux df command (Linux)
- Git large file storage will help handle large binary files (Linux)
- MySQL 5.7 and 5.6 group by differences (Database)
- VMWare virtual machine without rebooting way to add virtual disk (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.