Introduction to regular expressions (Microsoft) -- 10. Character matching

Source: Internet
Author: User

Character matching
The period (.) matches any single print or non-print character in a string, except the line break. The following Visual Basic Scripting Edition regular expressions can match 'aac ', 'abc', 'Acc', and 'adc, you 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 containing a file name, where the period (.) is a part of the input string, you can add a backslash () character before the period in the regular expression to achieve this requirement. For example, the following Visual Basic Scripting Edition regular expression can match 'filename. ext ':
/Filename. ext/
For VBScript, the equivalent expression is as follows:
"Filename. ext"
These expressions are still quite limited. They can only match any single character. In many cases, it is useful to match special characters from the list. For example, if the input text contains Chapter titles such as Chapter 1 and Chapter 2, you may need to find these Chapter titles.
Parentheses
You can add one or more single characters to a square brackets ([and]) to create a list to be matched. If the character is enclosed in parentheses, the list is called a bracket expression. Like any other place in brackets, normal characters represent themselves, that is, they match one of their own in the input text. Most special characters will lose their meaning in the brackets expression. Here are some exceptions:
1. The ']' character ends a list if it is not the first one. To match the ']' character in the list, place it in the first item, followed by the START.

2. ''is still used as an escape character. To match the ''character, use ''.
The characters contained in the brackets expression only match a single character that 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 title in VBScript, use the following expression:
"Chapter [1, 12345]"
Note that the word 'Chapter 'and the Space following it have a fixed relationship with the character positions in the brackets. Therefore, the bracket expression is only used to specify a character set that matches the position of a single character following the word 'Chapter 'and a space. This is the ninth character.
If you want to use a range rather than a character to represent the characters to be matched, you can use a hyphen to separate the start and end characters of the range. The character values of each character determine their relative sequence within a range. The following Visual Basic Scripting Edition regular expression contains a range expression 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.