Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Shell Programming Regular Expressions     - Ubuntu install VMware Workstation 11 tutorials at 14.04 / 14.10 (Linux)

- The correct way of logical backup mysqldump (Database)

- linux smartd [FAILED] appears at startup (Linux)

- Learning C language pointer essays (Programming)

- Linux Mint under tty.js Installation Guide (Linux)

- MySQL database to open a remote connection method (Database)

- CentOS6 installed Tomcat (Server)

- CentOS 6.0 system security level (Linux)

- MySQL + Heartbeat + DRBD deployment architecture (Server)

- CentOS7 Minimal minimize installation and then install the GNOME graphical interface (Linux)

- How to choose the correct HTTP status code (Server)

- View and modify Linux machine name (Linux)

- STL source code analysis - iterator each container classification (Programming)

- You really do need to know a variety of programming languages (Programming)

- Linux System Getting Started Learning: Using yum to download the RPM package without installing (Linux)

- Linux kernel likely and unlikely to resolve macro definitions (Linux)

- CentOS7 + Redis Live Installation and Configuration (Linux)

- Bash job control (Linux)

- Linux, Apache Web site security settings (Linux)

- Firewall types and instructions (Linux)

 
         
  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
Characters
"[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

String

\ {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 \}"
     
         
       
         
  More:      
 
- Vim (Linux)
- Linux group account deletion, and other related operations (Linux)
- Red Hat Enterprise Linux 6.4 Configuring VNC Remote Desktop login access (Linux)
- CentOS 5.5 install ntop (Linux)
- Use HugePages optimize memory performance (Database)
- Linux virtual machine how to access the Internet in a virtual machine when using NAT mode (Linux)
- Oracle to use full-text indexing (Database)
- JBPM6 Tutorial - taught you how to install JBPM (Linux)
- RegExp object implements regular match --JavaScript (Programming)
- RHEL / CentOS / Fedora Install Nagios 4.0.1 (Linux)
- YUM install desktop environment in CentOS (Linux)
- 3 ways to create a lightweight, durable system of Ubuntu Linux USB disk (Linux)
- 11 examples in Linux df command (Linux)
- Linux Network Programming - signal blocking and shielding (block, unblock) (Programming)
- Using Maven to download Spring (Linux)
- Use source packages compiled and installed GCC5.1 in Mac OS X 10.10.3 (Linux)
- Memcached source installation and configuration under CentOS 6.6 (Server)
- Check with Hello World Docker installation (Server)
- Ubuntu install Eclipse for C / C ++ and related configuration (Linux)
- Installation Sublime Text 3 (Build 3065) text editor in Ubuntu (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.