In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the regular expression in VBS how to achieve character matching, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Character matching
Period (.) Matches any single printed or non-printed character in a string, except for the newline character (\ n). The following Visual Basic Scripting Edition regular expressions can match 'aac',' abc', 'acc',' adc', and so on, as well as' A1c', 'a2c', 'Amurc' and 'Amuc':
/ a.c/
The equivalent VBScript regular expression is:
"A.C"
If you try to match a string containing a file name with a period (.) Is part of the input string, you can achieve this requirement by adding a backslash (\) character before the period in the regular expression. For example, the following Visual Basic Scripting Edition regular expression matches' filename.ext':
/ filename\ .ext /
For VBScript, the equivalent expression is as follows:
"filename\ .ext"
These expressions are still quite limited. They are only allowed to match any single character. In many cases, it is useful for matching special characters from a list. For example, if the input text contains chapter titles represented by numbers such as Chapter 1, Chapter 2, and so on, you may need to find these chapter titles.
Parenthetical expression
You can put one or more single characters in a square bracket ([and]) to create a list to match. If a character is enclosed in parentheses, the list is called a parenthesis expression. In parentheses, as anywhere else, ordinary characters represent themselves, that is, they match where they appear in the input text. Most special characters lose their meaning when they are in parenthetical expressions. There are some exceptions:
If the'] 'character is not the first item, it ends a list. To match the'] 'character in the list, place it in the first item, immediately after the' ['at the beginning.
'\' is still an escape character. To match the'\ 'character, use'\'.
The characters contained in the parenthesis expression match only one single character where the parenthesis expression 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 [12345]"
Notice that the position relationship between the word 'Chapter' and the spaces after it and the characters in parentheses is fixed. Therefore, parenthesis expressions are only used to specify a collection of characters that satisfy the position of a single character immediately after the word 'Chapter' and a space. Here is the ninth character position.
If you want to use a range instead of the character itself to represent the 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 in a range. The following Visual Basic Scripting Edition regular expression contains a range expression equivalent to the list of parentheses shown above.
/ Chapter [1-5] /
The expression for the same function in VBScipt is as follows:
"Chapter [1-5]"
If you specify a range in this way, both the start and end values are included in the range. It is particularly important to note that in Unicode sorting, the start value must precede the end value.
If you want to include a hyphen in a parenthesis expression, you must use one of the following methods:
Escape it with a backslash:
[\ -]
Place the hyphen at the beginning and end of the parenthesis list. The following expression matches all lowercase letters and hyphens:
[- a murz] [a murz -]
Creates a range in which the value of the start character is less than the hyphen and the value of the ending character is equal to or greater than the hyphen. The following two regular expressions meet this requirement:
[! -] [!-~]
Similarly, by placing a caret (^) at the beginning of the list, you can find all characters that are not in the list or range. If the caret appears elsewhere in the list, it matches itself without any special meaning. The following Visual Basic Scripting Edition regular expression matches chapter headings with chapter numbers greater than 5:
/ Chapter [^ 12345] /
For VBScript, use:
"Chapter [^ 12345]"
In the example shown above, the expression will match any numeric character except 1, 2, 3, 4, or 5 at the ninth position. Therefore, 'Chapter 7' is a match, and so is' Chapter 9'.
The above expression can be represented by a hyphen (-). For Visual Basic Scripting Edition, it is:
/ Chapter [^ 1-5] /
Or, for VBScript:
"Chapter [^ 1-5]"
A typical use of parenthesis expressions is to specify a match for any uppercase or lowercase alphabetic character or any number. The following Visual Basic Scripting Edition expression gives this match:
/ [A-Za-z0-9] /
The equivalent VBScript expression is:
"[A-Za-z0-9]" Thank you for reading this article carefully. I hope the article "how to achieve character matching in regular expressions in VBS" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.