Linux regular expression

Source: Internet
Author: User
Linux regular expression 1. some special symbols 2. first-line control character ^, last-line control character $ [html] find the first rule containing the: [root @ www ~] When grep-n&%39%%the&%39%regular_express.txt start with a lowercase letter: # grep-n & amp; #39; ^ [a-z] & amp; #39 ;... linux regular expression 1. some special symbols 2. first-line controller ^ and last-line controller $ [html] find the first controller that contains the: [root @ www ~] # Grep-n' ^ the 'regular_express.txt starts with a lowercase letter: # grep-n' ^ [a-z] 'regular_express.txt. if I do not want to start with an English letter: # grep-n' ^ [^ a-zA-Z] 'regular_express.txt is not started with an English letter: [root @ www ~] # Grep-n' ^ [^ a-zA-Z] 'regular_express.txt shows a blank line: [root @ www ~] # Grep-n '^ $' regular_express.txt do not display blank rows and rows with # signs: # grep-v '^ $'/etc/syslog. conf | grep-v '^ #' 3. in the regular expression. ". "Represents an absolute meaning of any character, and" * "represents repeating the meaning of the previous one to infinity. [cpp] Searches for four characters starting with g and ending with d: # grep-n'g .. d 'regular_express.txt looking for oo, ooo, oooo, and so on? Data, that is, there must be at least two o: # grep-n 'Ooo * 'regular_express.txt (the first two o must exist, and the number of repeat operations of the third o is not limited) search for the string starting with g and ending with g. there can be none in the middle [root @ www ~] # Grep-n 'G. * g' regular_express.txt what do I do if I want to find two to five consecutive o strings? At this time, you have to use a limited range? Character. But {} has special significance in shell. You must use the escape character \ to make it meaningless. The syntax of limit {} is as follows. Suppose I want to find two o strings, which can be: [root @ www ~] # Grep-N'Go \ {2, 5 \} g' regular_express.txt 4. special characters in regular expressions (1) ^ word: the string to be searched (word) at the beginning of the line! Search for "#": grep-n' ^ # 'regular_express.txt (2) word $: set the end of the line !? Which row is printed? T ,? Guangdong Harmony and diarrhea? Nbsp; search for "!" Ending with: grep-n '! $ 'Regular_express.txt (3) \: add a special symbol? Special meaning removed! Search for the line with T single quotes: grep-n \ 'regular_express.txt (4) *: there are no to infinite duplicates? The first character starts with Elasticsearch, and the second character repeats more than two times: grep-n 'ess * 'regular_express.txt (5) [list]: RE character of character set, it lists the characters you want to select! Search for lines of gl or gd: grep-n 'g [ld]' regular_express.txt (6) character set combined with RE characters, which lists strings that do not match the range! The searched string can be (oog) (ood) but not (oot): rep-n 'oo [^ t] 'regular_express.txt (7) [n1-n2]: character set, which lists the range of characters you want to include! Search for: grep-n '[0-9]' regular_express.txt (8) \ {n, m \} with numbers \}: search for strings with 2 to 3 o between n to m consecutive "First RE character" and g without g: grep-n 'go \ {2, 3 \} g' regular_express.txt
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.