Introduction to Regular Expressions (Microsoft)--11. Qualifier

Source: Internet
Author: User
Tags regular expression
Qualifier
Sometimes you don't know how many characters to match. To accommodate this uncertainty, regular expressions support the concept of qualifiers. These qualifiers can specify how many times a given component of a regular expression must appear to satisfy a match.
The following table gives a description of the various qualifiers and their meanings:
Character description
* Match the preceding subexpression 0 or more times. For example, zo* can match "z" and "Zoo".
* is equivalent to {0,}.
+ matches the preceding subexpression one or more times. For example, ' zo+ ' can match "Zo" to
and "Zoo", but cannot match "Z". + is equivalent to {1,}.
? Match the preceding subexpression 0 times or once. For example, "Do (es)" can match "do"
Or "Do" in "does". is equivalent to {0,1}.
{n} n is a non-negative integer. Matches the determined n times. For example, ' o{2} ' cannot match ' Bob '
"O" in, but can match two o in "food".
{N,} n is a non-negative integer. Match at least n times. For example, ' o{2,} ' cannot match ' Bob '
' O ', but can match all o in ' Foooood '. ' O{1,} ' is equivalent to ' o+ '. ' O
{0,} ' is equivalent to ' o* '.
{n,m} m and n are non-negative integers, where n <= m. Matches n times at least and matches up to M times.
Liu, "o{1,3}" will match the first three o in "Fooooood". ' o{0,1} ' equivalence
In ' O '. Notice that there is no space between the comma and the two number.
For a large input document, the number of chapters is easily more than nine chapters, so a method is needed to handle the two-digit or three-digit chapter number. Qualifier provides this functionality. The following visual Basic scripting Edition regular expressions can match chapter headings 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 will apply to the entire range expression contained, and in this case, only numbers from 0 to 9 are specified.
The ' + ' qualifier is not used here because a number is not necessarily required for the second or subsequent position. The '? ' character is also not used because it will limit the number of chapters to only two digits. You must match at least one number after the ' Chapter ' and the space character.
If you know that the chapter limit is only 99 chapters, you can use the following Visual Basic scripting Edition expression to specify at least one digit, but not more than two digits.
/chapter [0-9]{1,2}/
You can use the following regular expression 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.