Regular Expression introduction (Microsoft) -- 11. Qualifier

Source: Internet
Author: User

Qualifier
Sometimes I don't know how many characters to match. To adapt to this uncertainty, regular expressions support the concept of delimiters. These qualifiers can specify how many times a given component of a regular expression must appear to match.
The following table describes the delimiters and their meanings:
Character Description
* Matches the previous subexpression zero or multiple times. For example, zo * can match "z" and "zoo ".
* Is equivalent to {0 ,}.
+ Match the previous subexpression once or multiple times. For example, 'Zo + 'can match "zo"
And "zoo", but cannot match "z ". + Is equivalent to {1 ,}.
? Match the previous subexpression zero or once. For example, "do (es )? "Can match" do"
Or "do" in "does ".? It is equivalent to {0, 1 }.
{N} n is a non-negative integer. Match n times. For example, 'O {2} 'cannot match "Bob"
But can match the two "food.
{N,} n is a non-negative integer. Match at least n times. For example, 'O {2,} 'cannot match "Bob"
But can match all the o in "foooood. 'O {1,} 'is equivalent to 'o + '. 'O
{0,} 'is equivalent to 'o *'.
Both {n, m} m and n are non-negative integers, where n <= m. Match at least n times and at most m times.
Liu, "o {1, 3}" will match the first three o in "fooooood. 'O {0, 1} 'is equivalent
On 'o? '. Note that there must be no space between a comma and two numbers.
For a very large input document, the number of chapters is easily more than nine chapters, so there is a way to deal with two or three-digit number of chapters. The qualifier provides this function. The following Visual Basic Scripting Edition regular expression can match chapter titles with any number of digits:
/Chapter [1-9] [0-9] */
The following VBScript Regular Expression performs the same match:
"Chapter [1-9] [0-9] *"
Note that the qualifier appears after the range expression. Therefore, it applies to the entire range expression. In this example, only numbers from 0 to 9 are specified.
The '+' qualifier is not used here, Because a number is not required for the second or subsequent positions. '? 'Character, because this limits the number of chapters to only two digits. At least one number must be matched after 'Chapter 'and space characters.
If the number of chapters is limited to 99, you can use the following Visual Basic Scripting Edition expression to specify at least one digit, but no more than two digits.
/Chapter [0-9] {1, 2 }/
You can use the following regular expressions for VBScript:
"Chapter [0-9] {1, 2 }"

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.