The application of regular expression in Network programming (2)

Source: Internet
Author: User
Tags character set end expression integer numeric range regular expression string
Programming | network | syntax rules and tags for regular regular expressions

Now we formally enter the expression of learning, I will be based on the example of a combination of regular expression of the use, after reading you will feel that writing UBB code so simple, as long as you follow me step-by-Step after reading this article you become a UBB master. The exciting thing is that you can write your own UBB tags and no longer have to go to other people to copy ready-made code and templates. Fortunately VBScritp5.0 gave us a "regular expression" object, as long as your server installed ie5.x, you can run.

Character Description:

^ symbol matches the beginning of a string. For example:

^ABC matches "ABC XYZ" and does not match "XYZ ABC"

The $ symbol matches the end of the string. For example:

abc$ matches "xyz ABC" and does not match "ABC XYZ".

Note: If you use both the ^ symbol and the $ symbol, an exact match will be made. For example:

^abc$ only matches "ABC"

The * symbol matches 0 or more preceding characters. For example:

ab* can match "AB", "ABB", "abbb", etc.

The + symbol matches at least one of the preceding characters. For example:

Ab+ can match "ABB", "ABBB" and so on, but does not match "AB".

The symbol matches 0 or 1 preceding characters. For example:

Ab?c? Can and only match "abc", "Abbc", "ABCC" and "ABBCC"

. A symbol matches any character other than a newline character. For example:

(.) + matches all strings except line breaks

X|y matches "x" or "Y". For example:

ABC|XYZ can match "abc" or "XYZ", while "AB (c|x) yz" matches "Abcyz" and "abxyz"

{n} matches the preceding character of exactly n times (n is a non-negative integer). For example:

A{2} can match "AA", but does not match "a"

{N,} matches the preceding character at least n times (n is a non-negative integer). For example:

A{3,} matches "AAA", "AAAA" and so on, but does not match "a" and "AA".

Note: A{1,} is equivalent to A +

A{0,} equivalent to A *

{M,n} matches at least m, at most n preceding characters. For example:

a{1,3} only matches "a", "AA" and "AAA".

Note: a{0,1} is equivalent to a?

[XYZ] Represents a character set that matches one of the characters in parentheses. For example:

[ABC] matches "a", "B", and "C"

[^XYZ] Represents a negative character set. Matches any character that is not in this bracket. For example:

[^ABC] can match any character except "A", "B" and "C"

[A-z] represents a range of characters that matches any character within a specified interval. For example:

[A-z] matches any lowercase letter character between "a" and "Z"

[^m-n] represents a character outside a range that matches characters that are not in the specified range. For example:

[M-n] matches any character except from "M" To "N"

\ symbol is an escape operator. For example:

\ n Line Feed

\f Page Break

\ r Carriage Return

\ t tab

\v Vertical Tab

\ \ Match "\"

\/Match "/"

\s any white characters, including spaces, tabs, page breaks, and so on. Equivalent to "[\f\n\r\t\v]"

\s any characters that are not blank. Equivalent to "^\f\n\r\t\v]"

\w any word characters, including letters and underscores. Equivalent to "[a-za-z0-9_]"

\w any non word characters. Equivalent to "[^a-za-z0-9_]"

\b Matches the end of a word. For example:

ve\b match the word "love" and so on, but do not match "very", "even" and so on

\b Matches the beginning of a word. For example:

ve\b matches the word "very" and so on, but does not match "love" and so on

\d matches a numeric character, equivalent to [0-9]. For example:

ABC\DXYZ matching "abc2xyz", "abc4xyz" and so on,
But does not match "abcaxyz", "abc-xyz" and so on

\d matches a non-numeric character, equivalent to [^0-9]. For example:

ABC\DXYZ matching "abcaxyz", "abc-xyz" and so on,
But does not match "abc2xyz", "abc4xyz" and so on

\num matches num (where num is a positive integer), and the reference returns to the remembered match. For example:

(.) \1 matches two consecutive identical characters.

\onum matches N (where n is a octal value less than 256). For example:

\o011 Matching tab

\xnum matches num (where num is a hexadecimal swap value less than 256). For example:

\x41 matching character "A"



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.