Enabling Debug Mode
To enable script in debug mode, following actions to be performed by the user:
• On the Tools menu, click Internet Options.
• In the Internet Options dialog box, click the Advanced tab.
• In the Browsing category, clear the Disable script debugging check box.
• Click OK.
• Exit and restart Internet Explorer.
What are Regular Expressions?
Regular Expressions is a sequence of characters that forms
a pattern, which is mainly used for search and replace.
The purpose of creating a pattern is to match specific
strings, so that the developer can extract characters
based on conditions and replace certain characters.
RegExp Object
RegExp object helps the developers to match the pattern
of strings and the properties and methods help us to work
with Regular Expressions easily. It is similar to RegExp in JavaScript
Properties
• Pattern - The Pattern method represents a string that
is used to define the regular expression and it should
be set before using the regular expression object.
• IgnoreCase - A Boolean property that represents if the
regular expression should be tested against all possible
matches in a string if true or false. If not specified
explicitly, IgnoreCase value is set to False.
• Global - A Boolean property that represents if the regular
expression should be tested against all possible matches in
a string. If not specified explicitly, Global value is set to False.
Methods
• Test (search-string) - The Test method takes a string as
its argument and returns True if the regular expression can
successfully be matched against the string, otherwise False is returned.
• Replace (search-string, replace-string) - The Replace method
takes 2 parameters. If the search is successful then it
replaces that match with the replace-string, and the new
string is returned. If there are no matches then the original search-string is returned.
• Execute (search-string) - The Execute method works like
Replace, except that it returns a Matches collection object,
containing a Match object for each successful match. It doesn't modify the original string.
Matches Collection Object
The Matches collection object is returned as a result of
the Execute method. This collection object can contain
zero or more Match objects and the properties of this object are read-only.
• Count - The Count method represents the number of match objects in the collection.
• Item - The Item method enables the match objects to be accessed
from matches collections object.
Match Object
The Match object is contained within the matches collection object.
These objects represent the successful match after the search for a string.
• FirstIndex - It represents the position within the original
string where the match occurred. This index are zero-based which
means that the first position in a string is 0.
• Length - A value that represents the total length of the matched string.
• Value - A value that represents the matched value or text.
It is also the default value when accessing the Match object.
All about Pattern Parameter
The pattern building is similar to PERL. Pattern building is
the most important thing while working with Regular Expressions.
In this section, we will deal with how to create a pattern based on various factors.
Position Matching
The significance of position matching is to ensure that we place
the regular expressions at the correct places.