Codecore Logo
Quick Search
»
Advanced Search »

RegEx Object

RSS
Represents an immutable regular expression.


Constructors

RegEx( String )

Initializes and compiles a new instance of the RegEx class for the specified regular expression.

Syntax:

RegEx( String pattern )

Parameters:

pattern: The regular expression pattern to match.

Example:


r = new RegEx(@"(a|b|r)+");

RegEx( String, String )

Initializes and compiles a new instance of the Regex class for the specified regular expression, with options that modify the pattern.

Syntax:

RegEx( String pattern, String options )

Parameters:

pattern: The regular expression pattern to match.
options: A bitwise OR combination of Regex Option values. 0=None, 1=Case-insensitive, 2=Multi-line, 4=Explicit Capture, 8=Compiled, 16=Single Line, 32=Ignore Pattern Whitespace, 64=Right To Left, 256=ECMA Script, 512=Culture Invariant

Example:


r = new RegEx(@"(a|b|r)+", 1);

Instance Properties

IsCaseInsensitive

Gets a value indicating whether the regular expression searches from right to left.

Accessibility : Read Only

Type: Boolean

Example:


r = new RegEx(@"(a|b|r)+", 1);
b = r.IsCaseInsensitive; // results in true

IsRightToLeft

Gets a value indicating whether the regular expression searches from right to left.

Accessibility : Read Only

Type: Boolean

Example:


r = new RegEx(@"(a|b|r)+", 1);
b = r.IsRightToLeft; // results in false

Options

Returns the options passed into the Regex constructor. 0=None, 1=Case-insensitive, 2=Multi-line, 4=Explicit Capture, 8=Compiled, 16=Single Line, 32=Ignore Pattern Whitespace, 64=Right To Left, 256=ECMA Script, 512=Culture Invariant

Accessibility : Read Only

Type: Number

Example:


r = new RegEx(@"(a|b|r)+", 1);
options = r.Options; // results in 1

Instance Methods

IsMatch ( String )

Indicates whether the regular expression finds a match in the input string using the regular expression specified in the pattern parameter.

Syntax:

Boolean IsMatch( String input )

Parameters:

input: The string to search for a match.

Return Value

true if the regular expression finds a match; otherwise, false

Example:


r = new RegEx(@"(a|b|r)+", 1);
b = r.IsMatch("a");

IsMatch ( String, Number )

Indicates whether the regular expression specified in the Regex constructor finds a match in the input string beginning at the specified starting position in the string.

Syntax:

Boolean IsMatch( String input, Number startAt )

Parameters:

input: The string to search for a match.

startAt: The character position at which to start the search.

Return Value

true if the regular expression finds a match; otherwise, false

Example:


r = new RegEx(@"(a|b|r)+", 1);
b = r.IsMatch("abcdefgh", 3);

Match ( String )

Searches the specified input string for all occurrence of the regular expression specified in the Regex constructor.

Syntax:

Array Match( String input )

Parameters:

input: The string to search for a match.

Return Value

An array of matched strings.

Example:


r = new RegEx(@"(a|b|r)+");
return r.Match("abracadabra"); // Results in an array of "abra" , "a", "abra".

Split( String )

Splits the specified input string a specified maximum number of times at the positions defined by a regular expression specified in the RegEx constructor.

Syntax:

Array Match( String input )

Parameters:

input: The string to split.

Return Value

An array of strings.

Example:


r = new RegEx(@"(-)");
return r.Split("red-green-blue"); // Results in an array of "red", "-", "green", "-", "blue"

Split( String, Number )

Splits the specified input string a specified maximum number of times at the positions defined by a regular expression specified in the RegEx constructor.

Syntax:

Array Match( String input, Number count )

Parameters:

input: The string to split.

count: The maximum number of times the split can occur.

Return Value

An array of strings.

Example:


r = new RegEx(@"(-)");
return r.Split("red-green-blue", 2); // Results in an array of "red", "-", "green-blue"

Split( String, Number, Number )

Splits the specified input string a specified maximum number of times at the positions defined by a regular expression specified in the RegEx constructor. The search for the regular expression pattern starts at a specified character position in the input string.

Syntax:

Array Match( String input, Number count, Number startAt )

Parameters:

input: The string to split.

count: The maximum number of times the split can occur.

startAt: The character position in the input string where the search will begin.

Return Value

An array of strings.

Example:


r = new RegEx(@"(-)");
return r.Split("red-green-blue", 2, 5); // Results in an array of "red-green", "-", "blue"

Static Methods

IsMatch ( String, String )

Indicates whether the regular expression finds a match in the input string using the regular expression specified in the pattern parameter.

Syntax:

Boolean IsMatch( String input, Number pattern )

Parameters:

input: The string to search for a match.

pattern: The regular expression pattern to match.

Return Value

true if the regular expression finds a match; otherwise, false

Example:


b = RegEx.IsMatch("abcdefgh", @"(a|b|r)+");

Match ( String, String )

Searches the specified input string for an occurrence of the regular expression supplied in the pattern parameter.

Syntax:

Array Match( String input, Number pattern )

Parameters:

input: The string to search for a match.

pattern: The regular expression pattern to match.

Return Value

An array of matched strings.

Example:


return RegEx.Match("abracadabra", @"(a|b|r)+"); // Results in an array of "abra" , "a", "abra".

Split( String, String )

Splits the input string at the positions defined by a regular expression pattern.

Syntax:

Array Match( String input, String pattern )

Parameters:

input: The string to split.

pattern: The regular expression pattern to match.

Return Value

An array of strings.

Example:


return RegEx.Split(@"(-)", "red-green-blue"); // Results in an array of "red", "-", "green", "-", "blue"
Privacy Policy | Conditions Of Use

Copyright ©2014 Codecore Technologies, All rights reserved.