Regularexpression=/pattern/[switch]
There are three values of this switch: Global Match i: Ignore case gi: Global Match + Ignore case JScript Language Reference
--------------------------------------------------------------------------------
One of the most important features of backward reference regular expressions is the ability to store a part of the matching successful pattern for later use. Recall that adding parentheses to both sides of a regular expression pattern or partial pattern will cause the partial expression to be stored in a temporary buffer. The non-capturing metacharacter '?:', '?=', or '?!' can be used to ignore the storage of this part of the regular expression.
Each submatch captured is stored as the content encountered from left to right in the regular expression pattern. The buffer number that stores sub-matches starts at 1 and is consecutively numbered up to a maximum of 99 sub-expressions. Each buffer can be accessed using '/n', where n is a one- or two-digit decimal number that identifies a particular buffer.
Backward citation One of the easiest and most useful applications is the ability to determine the locations of two identical words in a word. Please see the following sentence: Is is the cost of gasoline going up up? According to the written content, the above sentence obviously has the problem of repeated words. It would be great if there was a way to modify the sentence without looking for repetition of each word. The following JScript regular expression can achieve this function using a subexpression.
//b([az]+) /1/b/gi equivalent VBScript expression is:
"/b([az]+) /1/b" In this example, the subexpression is each item between parentheses. The captured expression includes one or more alphabetical characters, i.e. specified by '[az]+'. The second part of the regular expression is a reference to the previously captured sub-match, that is, the second occurrence of the word matched by the additional expression. '/1' is used to specify the first submatch. Word boundary element characters ensure that only individual words are detected. If not, phrases such as "is issued" or "this is" will be incorrectly recognized by the expression.
In a JScript expression, the global flag ('g') following the regular expression means that the expression will be used to find as many matches as possible in the input string. Case sensitivity is specified by the case sensitivity mark ('i') at the end of the expression. Multi-line tags specify potential matches that may appear at both ends of a newline character. For VBScript, various tags cannot be set in expressions, but they must be explicitly set using the properties of the RegExp object.
Using the regular expression shown above, the following JScript code can replace the same word that appears twice in a literal string with the same word using sub-match information:
var ss = "Is is the cost of gasoline going up up?./n"; var re = //b([az]+) /1/b/gim; //Create regular expression style.var rv = ss.replace(re,"$1"); //Replace two words with one word.