1. Creating the object.
RegExp = Новый COMОбъект("VBScript.RegExp");
2. Properties.
| Property | Data Type | Description | Default Value | Example |
|---|---|---|---|---|
| Global | Boolean | Check the string up to the first pattern match (False) or throughout the entire text (True) | False |
|
| IgnoreCase | Boolean | Case-sensitive (False) or case-insensitive (True) | False |
|
| MultiLine | Boolean | Multi-line (True) or single-line (False) mode | False |
|
| Pattern | String | The pattern used – a text sample consisting of ordinary characters and/or special metacharacters |
|
3. Methods.
| Method | Description | Return Value | Example |
|---|---|---|---|
| Replace(String, Substring) | Replaces occurrences matching the pattern (Pattern property) in the original string with the specified substring | Modified string |
|
| Test(String) | Checks if the string matches the pattern | Boolean |
|
| Execute(String) | Finds occurrences in the original string that match the pattern | Collection of found substrings as a composite object |
|
4. Metacharacters.
| Characters | Description | Example |
|---|---|---|
| \ | Indicates that the next character is a special character. The sequence "\\" corresponds to "\", and the sequence "\(" corresponds to "(". |
|
| ^ | Defines the beginning of the input string. If the Multiline property is set, it also defines the position immediately after "\n" (newline) and "\r" (carriage return). |
|
| $ | Defines the end of the input string. If the Multiline property is set, it also defines the position immediately before "\n" (newline) and "\r" (carriage return). |
|
| * | Defines zero or more characters preceding it. Equivalent to {0,}. |
|
| + | Defines one or more characters preceding it. Equivalent to {1,}. |
|
| ? | Defines zero or one character preceding it. Equivalent to {0,1}. If this metacharacter immediately follows constructs (*, +, ?, {n}, {n,}, {n,m}), it modifies the search algorithm as illustrated in the example below. |
|
| {n} | Defines an exact number of characters preceding it. "n" is a non-negative integer. |
|
| {n,} | Defines a minimum number of characters preceding it. "n" is a non-negative integer. "{0,}" is equivalent to "*", and "{1,}" is equivalent to "+". |
|
| {n,m} | Defines the number of characters preceding it (from n to m). "n" and "m" are non-negative integers, with n <= m. "{0,1}" is equivalent to "?". |
|
| . | Defines any character except "\n" (newline). To define any character including "\n", use "[\s\S]". |
|
| (pattern) | Captures the matched pattern into the SubMatches collection. To match the characters "(" and ")", use "\(" and "\)". |
|
| (?:pattern) | Useful for combining parts of a pattern using the "|" ("or") character. For example, "госпо(?:дин|жа)" is shorter than "господин|госпожа". Does NOT capture the match into the SubMatches collection. |
|
| (?=pattern) | "Windows(?=95|98)" matches the substring "Windows" in the string "Windows95", but not in "WindowsNT". The next match starts immediately, not after the characters within the parentheses. Does NOT capture the match into the SubMatches collection. |
|
| (?!pattern) | "Windows(?!95|98)" matches the substring "Windows" in the string "WindowsNT", but not in "Windows95". Otherwise, it is fully analogous to "(?=pattern)". |
|
| x|y | Logical "or" condition. "вз|перевод" matches "вз" and "перевод". "(вз|пере)вод" matches "взвод" and "перевод". |
|
| [abc] | Character set. Matches any of the specified characters. |
|
| [^abc] | Negated character set. Matches any character not specified. |
|
| [a-z] | Character range. Matches any character within the range. |
|
| [^a-z] | Negated character range. Matches any character that is not in the range. |
|
| \b \B | \b - Word boundary, i.e., the position between the end of a word and a space. \B - Non-word boundary. |
|
| \d \D | \d - Digit. Equivalent to [0-9]. \D - Non-digit. Equivalent to [^0-9]. |
|
| \w \W | \w - Any word character, including the underscore. Equivalent to [A-Za-z0-9_]. \W - Opposite of "\w". Equivalent to [^A-Za-z0-9_]. |
|
| \s \S | \s - Whitespace character. Equivalent to [\f\n\r\t\v]. \S - Non-whitespace character. Equivalent to [^\f\n\r\t\v]. |
|
| \cx | Control character. The parameter "x" must be in the range A-Z or a-z. For example, "\cM" represents Control-M or carriage return, "\cJ" represents a newline, "\cL" represents a form feed, "\cI" represents a tab, and "\cK" represents a vertical tab. |
|
| \f | Form feed character. Equivalent to "\x0c" and "\cL". | |
| \n | Newline character. Equivalent to "\x0a" and "\cJ". |
|
| \r | Carriage return character. Equivalent to "\x0d" and "\cM". |
|
| \t | Tab character. Equivalent to "\x09" and "\cI". |
|
| \v | Vertical tab character. Equivalent to "\x0b" and "\cK". |
|
| \xn | Hexadecimal ASCII code of a character. Must contain exactly two characters. |
|
| \num | Backreference to previously captured (matched) substrings (SubMatches). "num" is a positive integer representing the index of the match in the SubMatches collection; indexing starts at 1. For example, "(.)\1" matches two identical characters occurring consecutively. |
|
| \un | Defines a Unicode character by its hexadecimal code. "n" is a four-digit hexadecimal code. |
|
