In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how regular expressions are selected and marshalled in VBS. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Selection and grouping
Select to allow the use of the'| 'character to select between two or more candidates. By extending the regular expression of the chapter title, it can be extended to an expression that is not only applicable to the chapter title. But it's not as straightforward as you think. When using a selection, the most likely expression on each side of the'| 'character is matched. You might think that the following Visual Basic Scripting Edition and VBScript expressions would match 'Chapter' or' Section': at the beginning and end of a line followed by one or two numbers
/ ^ Chapter | Section [1-9] [0-9] {0jue 1} $/ "^ Chapter | Section [1-9] [0-9] {0jue 1} $"
Unfortunately, the real situation is that the regular expression shown above either matches the word 'Chapter',' at the beginning of the line or matches the 'Section' followed by any number at the end of the line. If the input string is' Chapter 22', the above expression will match only the word 'Chapter'. If the input string is' Section 22', the expression will match 'Section 22'. But this result is not our goal here, so there must be a way to make regular expressions more responsive to what you want to do, and there is indeed a way to do so.
You can use parentheses to limit the scope of the selection, that is, to make it clear that the choice applies only to the words' Chapter' 'and' Section'. However, parentheses are also difficult to deal with because they are also used to create subexpressions, some of which will be covered later in the subexpressions section. By taking the regular expression shown above and adding parentheses where appropriate, you can make the regular expression match either 'Chapter 1' or 'Section 3'.
The following regular expression uses parentheses to group 'Chapter' and' Section' so that the expression works correctly. For Visual Basic Scripting Edition, it is:
/ ^ (Chapter | Section) [1-9] [0-9] {0jue 1} $/
For VBScript, it is:
"^ (Chapter | Section) [1-9] [0-9] {0jue 1} $"
These expressions work correctly, but produce an interesting by-product. Placing parentheses on both sides of the 'Chapter | Section' establishes the appropriate grouping, but also causes one of the two words to be matched to be captured for future use. Because there is only one set of parentheses in the expression shown above, there can be only one captured submatch. This submatch can be referenced using the Submatches collection of VBScript or the $1 color 9 property of the RegExp object in Visual Basic Scripting Edition.
Sometimes capturing a submatch is desirable and sometimes undesirable. In the example shown in the explanation, what you really want to do is to use parentheses to group the choices between the words' Chapter' or 'Section'. You do not want to refer to the match later. In fact, do not use it unless you really need to capture a sub-match. Since it does not take time and memory to store those submatches, this regular expression will be more efficient.
You can use'?: 'before the inside of regular expression pattern parentheses to prevent the match from being stored for future use. The following modifications to the regular expressions shown above provide the same functionality that eliminates sub-matching storage. For Visual Basic Scripting Edition:
/ ^ (?: Chapter | Section) [1-9] [0-9] {0jue 1} $/
For VBScript:
"^ (?: Chapter | Section) [1-9] [0-9] {0jue 1} $"
In addition to the'?: 'metacharacter, there are two uncaptured metacharacters for what is called a pre-check match. One is a forward preview, denoted by? = to match the search string at any location where the regular expression pattern in parentheses begins to match. One is negative pre-check, use'?!' Indicates that the search string is matched at any location where the regular expression pattern is not initially matched.
For example, suppose you have a document that contains references to Windows 3.1, Windows 95, Windows 98, and Windows NT. Further assume that you need to update the document by looking for all references to Windows 95, Windows 98, and Windows NT and changing those references to Windows 2000. You can use the following Visual Basic Scripting Edition regular expression, which is a forward preview to match Windows 95, Windows 98, and Windows NT:
/ Windows (? = 95 | 98 | NT) /
To make the same match in VBScript, you can use the following expression:
"Windows (? = 95 | 98 | NT)"
When a match is found, the search for the next match begins immediately after the matching text (excluding the characters used in the pre-search). For example, if the expression shown above matches' Windows 98', the search will continue after 'Windows'' instead of'98'.
Thank you for reading! This is the end of this article on "how to select and group regular expressions in VBS". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.