Regular Expressions--metacharacters

Source: Internet
Author: User

To learn the regular expression, understanding meta-characters is a must to overcome the difficulties.
Don't try to remember.
.: matches any single character.
For example, the regular expression "B.G" can match the following string: "Big", "Bug", "BG", but does not match "Buug", "B." G "Can match" Buug ". []: Matches any one of the characters in the parentheses.
For example, the regular expression "b[aui]g" matches the bug, big and bag, but does not match beg, Baug. You can use the hyphen "-" in parentheses to specify the interval of the character to simplify the representation, such as the regular expression [0-9] can match any numeric character, so that the regular expression "a[0-9]c" equivalent to "a[0123456789]c" can Match "a0c", "A1c", "A2C" such as String, you can also create multiple intervals, such as "[A-za-z]" can match any uppercase and lowercase letters, "[a-za-z0-9]" can match any uppercase or lowercase letters or numbers. (): The expression that is enclosed in () is defined as "group", and the character that matches the expression is saved to a staging area, which is useful when the string is extracted. To represent some characters as a whole. Change the priority, define the extraction group of two roles. : A logical OR operation of two matching criteria.
' Z|food ' can match "z" or "food". ' (z|f) Ood ' matches "Zood" or "food".

*: Match 0 to more sub-expressions before it, and wildcards * okay.
For example, the regular expression "zo*" can Match "Z", "Zo" and "Zoo", so ". *" means that you can match any string. "Z (b|c) *" →zb, ZBC, ZCB, ZCCC, ZBBBCCC. "Z (AB) *" can match Z, Zab, Zabab (with parentheses to change precedence). +: Matches the preceding subexpression one or more times, and * contrasts (0 to multiple).
For example, the regular expression + + matches 9, 99, 999, and so on. "zo+" can Match "Zo" and "Zoo" and cannot match "Z".? : matches the preceding subexpression 0 or one time.
For example, "Do (es)?" You can match "do" or "does". Typically used to match the "optional section". {n}: matches the determined n times.
"Zo{2}" →zoo. For example, "e{2}" cannot match "E" in "bed", but can match two "E" in "seed".
{N,}: matches at least n times.
For example, "e{2,}" cannot match "E" in "bed", but can match all "E" in "Seeeeeeeed". {n,m}: matches at least n times and matches up to M times.
"e{1,3}" will match the first three "E" in "Seeeeeeeed"

^ (shift+6): Matches the start of a row.
For example, the regular expression "^regex" can match the beginning of the string "Regex I will use", but does not match "I will use regex". ^ Another meaning: No! (not understood at the moment) $: Match line terminator.
For example, the regular expression "cloud $" can match the string "Everything is a cloud" end, but cannot match the string "floating clouds Ah"

Regular Expressions--metacharacters

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.