Introduction of regular Expressions (Microsoft)--10. Character Matching

Source: Internet
Author: User
Tags character set regular expression
Character matching
a period (.) matches any single printed or nonprinting character in a string, except for line breaks (). The following Visual Basic scripting Edition Regular expressions can match ' AAC ', ' abc ', ' ACC ', ' ADC ' and so on, and can also match ' A1c ', ' a2c ', a-c ' and a#c ':
/a.c/
The equivalent VBScript regular expression is:
"A.C"
If you try to match a string that contains a filename, where the period (.) is part of the input string, you can implement this requirement by preceding the period in the regular expression with a backslash () character. For example, the following Visual Basic scripting Edition Regular expressions can match ' filename.ext ':
/filename.ext/
For VBScript, an equivalent expression looks like this:
"Filename.ext"
These expressions are still quite limited. They only allow matching of any single character. In many cases, it is useful to match Special characters from a list. For example, if your input text contains chapter headings that are represented numerically as Chapter 1, Chapter 2, and so on, you may need to find these chapter headings.
Bracket expression
You can create a list to match by putting one or more single characters in a square bracket ([and]). If the character is enclosed in parentheses, the list is called a bracket expression. In parentheses and anywhere else, ordinary characters represent themselves, that is, they match the one that appears in the input text. Most special characters lose their meaning when they are in a bracket expression. Here are some exceptions:
1. '] ' character if it is not the first item, a list will be closed. To match the '] ' character in the list, place it in the first item, immediately after the start ' ['.

2. "" is still an escape character. To match the ' character, please use '.
The characters contained in the bracket expression match only a single character of the bracket expression where it is located in the regular expression. The following Visual Basic scripting Edition Regular expressions can match ' Chapter 1 ', ' Chapter 2 ', ' Chapter 3 ', ' Chapter 4 ', and ' Chapter 5 ':
/chapter][12345]/
To match the same chapter headings in VBScript, use the following expression:
"Chapter [12345]"
Note that the word ' Chapter ' and the following spaces are fixed with the position of the characters in parentheses. Therefore, the bracket expression is used only to specify a character set that satisfies the single characters position immediately following the word ' Chapter ' and a space. This is the Nineth character position.
If you want to use a range instead of the character itself to represent a character to be matched, you can use a hyphen to separate the start and end characters of the range. The character value of each character determines its relative order within a range. The following Visual Basic scripting Edition Regular expression contains a range expression that is equivalent to the list of parentheses shown above.

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.