Select Allows the use of '|' characters to select in two or more candidates. By expanding the regular expression of the title, it can be expanded to express the expression of the chapter title not only. However, this can not be imagined directly. When using the selected selection, the most likely expression of the '|' character is matched. You may think that the JScript and VBScript expressions below will match the beginning and end position of a row and follow one or two numbers' or 'section':
/ ^ Chapter | Section [1-9] [0-9] {0,1} $ /
"^ Chapter | Section [1-9] [0-9] {0,1} $
Unfortunately, the true situation is that the regular expression above is either matches the word 'Chapter' at the beginning of a row, or it is matched to the end of the end with any number's 'section'. If the input string is 'Chapter 22', the above expression will only match the word 'chapter'. If the input string is 'section 22', the expression will match 'section 22'. But this result is not our purpose here, so there must be an approach to make the regular expression more easily respond to what you want, and there is indeed this method.
Parentheses can be used to limit the range of choices, that is, the choice is only suitable for both words 'Chapter' and 'Section'. However, parentheses are also difficult because they are also used to create sub-expression, and some content will be introduced behind the sub-expression. By adopting the regular expression above and adding parentheses in the appropriate position, the regular expression can be matched to 'chapter 1', or the 'section 3' can also be matched.
The following regular expression uses parentheses to form a group of 'chapter' and 'section', so the expression can work correctly. For JScript:
/ ^ (Chapter | section) [1-9] [0-9] {0,1} $ /
For VBScript:
"^ (Chapter | section) [1-9] [0-9] {0,1} $
These expressions are correct, just generate an interesting by-product. The appropriate grouping is established in the 'Chapter | Section' on both sides, but it also causes one of the two to match words to be used in the future. Since there is only one group of parentheses in the expression shown above, there can be only one captured Submatch. This sub-match can be referenced using the Submatches collection of VBScript or the $ 1- $ 9 attribute of the REGEXP object in JScript.
Sometimes it is desirable to capture a child, sometimes it is undesirable. In the example shown, it is really desirable to use parentheses to group the selection group between the word 'Chapter' or 'Section'. It does not want to reference this match later. In fact, please do not use it unless it is really a capture match. Since there is no need to spend time and memory, this regular expression will be higher.
You can use '?:' To prevent storage of this match from being used in the future in the regular expression pattern parentheses. The following modifications to the regular expressions shown above provide the same functionality of exempting sub-match storage. For JScript:
/ ^ (?: chapter | section) [1-9] [0-9] {0,1} $ /
For VBScript:
"^ (?: chapter | section) [1-9] {0,1} $
In addition to '?:' Metamorphic, there are two nonaptured metammatics to call them. One is positive forecast, with? = Indicated that the search string is matched in any position where the regular expression mode in the parentheses is matched. One is a negative forecast, with '?!', Indicating that the search string is matched without matching the regular expression mode. For example, assume that there is a document containing a reference to Windows 3.1, Windows 95, Windows 98, and Windows NT. Further assume that this document needs to be updated, the method is to find all references to Windows 95, Windows 98, and Windows NT and change these references to Windows 2000. You can use the following JScript regular expressions, this is a forward review to match Windows 95, Windows 98, and Windows NT:
/ Windows (? = 95 | 98 | NT) /
The same matches to do in VBScript can use the following expression:
"? = 95 | 98 | NT)"
After finding a match, the text matched immediately (not the character used in the pre-examined) begins to search the next time. For example, if the expression shown above matches the 'Windows 98', will continue to find from 'Windows' instead of '98'.