Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Description of VBS regular expression locator

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "description of VBS regular expression locators". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn the description of VBS regular expression locator.

Locator

So far, the examples you have seen have only considered looking for chapter titles that appear anywhere. Any string 'Chapter' that appears, followed by a space and a number, may be a real chapter title or a cross-reference to other chapters. Because the real chapter title always appears at the beginning of a line, you need to design a way to find only the title and not cross-references.

The locator provides this function. A locator can fix a regular expression at the beginning or end of a line. You can also create regular expressions that appear only within a word or at the beginning or end of a word. The following table contains a list of regular expressions and their meanings:

The character description ^ matches the starting position of the input string. If the Multiline property of the RegExp object is set, ^ also matches the position after'\ n'or'\ r'. $matches the end of the input string. If the Multiline property of the RegExp object is set, $also matches the position before'\ n'or'\ r'. \ b matches a word boundary, that is, the position between the word and the space. \ B matches non-word boundaries.

You cannot use qualifiers for locators. Because there are no consecutive positions before or after a newline character or word boundary, expressions such as'^ * 'are not allowed.

To match the text where a line of text begins, use the'^ 'character at the beginning of the regular expression. Do not confuse this syntax of'^ 'with its syntax in parenthetical expressions. Their grammar is fundamentally different.

To match the text at the end of a line of text, use the'$'character at the end of the regular expression.

To use locators when looking for chapter titles, the following Visual Basic Scripting Edition regular expression matches chapter headings with up to two numbers at the beginning of a line:

/ ^ Chapter [1-9] [0-9] {0jue 1} /

The regular expressions for the same functionality in VBScript are as follows:

"^ Chapter [1-9] [0-9] {0jue 1}"

A real chapter title appears not only at the beginning of a line, but also at the end of a line, so it must also be at the end of a line. The following expression ensures that the specified match matches only the chapter and not the cross-reference. It is achieved by creating a regular expression that matches only the beginning and end of a line of text.

/ ^ Chapter [1-9] [0-9] {0jue 1} $/

For VBScript, use:

"^ Chapter [1-9] [0-9] {0jue 1} $"

Matching word boundaries are slightly different, but add a very important function to regular expressions. The word boundary is the position between the word and the space. A non-word boundary is anywhere else. The following Visual Basic Scripting Edition expression matches the first three characters of the word 'Chapter' because they appear after the word boundary:

/\ bCha/

For VBScript, it is:

"\ bCha"

The position of the'\ b 'operator is critical here. If it is at the beginning of the string to match, the match at the beginning of the word is found; if it is at the end of the changed string, the match at the end of the word is found. For example, the following expression will match the ter', in the word 'Chapter'' because it appears before the word boundary:

/ ter\ b /

And

"ter\ b"

The following expression will match 'apt', because it is in the middle of' Chapter', but will not match 'apt':' in 'aptitude'

/\ Bapt/

And

"\ Bapt"

This is because the apt' appears at the non-word boundary in the word 'Chapter'' and at the word boundary in the word 'aptitude'. The position of the non-word boundary operator is not important because the match has nothing to do with the beginning or end of a word.

At this point, I believe you have a deeper understanding of the "description of VBS regular expression locators". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report