System::Text::RegularExpressions::Regex Class Reference

Inherits System::Object.

Public Member Functions

 Regex ()
 Constructs empty regexp. More...
 
 Regex (const String &pattern)
 
 Regex (const String &pattern, RegexOptions options)
 
 Regex (const String &pattern, RegexOptions options, TimeSpan matchTimeout)
 
virtual ~Regex ()
 Destructor. More...
 
TimeSpan get_MatchTimeout ()
 
RegexOptions get_Options ()
 
bool get_RightToLeft ()
 
bool IsMatch (const String &input, int startat=0)
 
MatchPtr Match (const String &input)
 
MatchPtr Match (const String &input, int startat, int length=0)
 
MatchCollectionPtr Matches (const String &input, int startat=0)
 
String Replace (const String &input, const String &replacement)
 
String Replace (const String &input, const char_t *replacement)
 
String Replace (const String &input, MatchEvaluator evaluator)
 
String Replace (const String &input, MatchEvaluator evaluator, int count)
 
String Replace (const String &input, MatchEvaluator evaluator, int count, int startat)
 
ArrayPtr< StringSplit (const String &input)
 
ArrayPtr< StringSplit (const String &input, int count)
 
String ToString () ASPOSE_CONST override
 
- Public Member Functions inherited from System::Object
 Object ()
 Creates object. Initializes all internal data structures. More...
 
virtual ~Object ()
 Destroys object. Frees all internal data structures. More...
 
 Object (Object const &x)
 Copy constructor. Doesn't copy anything, really, just initializes new object and enables copy constructing subclasses. More...
 
Objectoperator= (Object const &x)
 Assignment operator. Doesn't copy anything, really, just initializes new object and enables copy constructing subclasses. More...
 
ObjectSharedRefAdded ()
 Increments shared reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
int SharedRefRemovedSafe ()
 Decrements and returns shared reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
int RemovedSharedRefs (int count)
 Decreases shared reference count by specified value. More...
 
Detail::SmartPtrCounter * WeakRefAdded ()
 Increments weak reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
void WeakRefRemoved ()
 Decrements weak reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
Detail::SmartPtrCounter * GetCounter ()
 Gets reference counter data structure associated with the object. More...
 
int SharedCount () const
 Gets current value of shared refernce counter. More...
 
void Lock ()
 Implements C# lock() statement locking. Call directly or use LockContext sentry object. More...
 
void Unlock ()
 Implements C# lock() statement unlocking. Call directly or use LockContext sentry object. More...
 
virtual bool Equals (ptr obj)
 Compares objects using C# Object.Equals semantics. More...
 
virtual int GetHashCode () const
 Analog of C# Object.GetHashCode() method. Enables hashing of custom objects. More...
 
virtual ptr MemberwiseClone () const
 Analog of C# Object.MemberwiseClone() method. Enables cloning custom types. More...
 
virtual const TypeInfoGetType () const
 Gets actual type of object. Analog of C# System.Object.GetType() call. More...
 
virtual bool Is (const TypeInfo &targetType) const
 Check if object represents an instance of type described by targetType. Analog of C# 'is' operator. More...
 
virtual void SetTemplateWeakPtr (unsigned int argument)
 Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containers to weak mode. More...
 
template<>
bool Equals (float const &objA, float const &objB)
 
template<>
bool Equals (double const &objA, double const &objB)
 
template<>
bool ReferenceEquals (String const &str, std::nullptr_t)
 
template<>
bool ReferenceEquals (String const &str1, String const &str2)
 

Static Public Member Functions

static String Replace (const String &input, const char_t *pattern, const char_t *replacement)
 
static String Replace (const String &input, const String &pattern, const char_t *replacement)
 
static String Replace (const String &input, const String &pattern, const String &replacement, RegexOptions options)
 
static String Replace (const String &input, const String &replacement, int count)
 Replaces substrings in string. Not implemented. More...
 
static bool IsMatch (const String &input, const String &pattern, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout, int startat=0)
 
static MatchPtr Match (const String &input, const String &pattern, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout, int startat=0, int length=0)
 
static MatchCollectionPtr Matches (const String &input, const String &pattern, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout, int startat=0, int length=0)
 
static String Replace (const String &input, const String &pattern, const String &replacement)
 
static String Replace (const String &input, const String &pattern, MatchEvaluator evaluator)
 
static ArrayPtr< StringSplit (const String &input, const String &pattern, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout)
 
static ArrayPtr< StringSplit (const String &input, const String &pattern, int count, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout)
 
static String Escape (const String &str)
 
static String Unescape (const String &str)
 
- Static Public Member Functions inherited from System::Object
static bool ReferenceEquals (ptr const &objA, ptr const &objB)
 Compares objects by reference. More...
 
template<typename T >
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, T const &objB)
 Compares objects by reference. More...
 
template<typename T >
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, std::nullptr_t)
 Reference-compares value type object with nullptr. More...
 
template<typename T1 , typename T2 >
static std::enable_if< IsSmartPtr< T1 >::value &&IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 Compares reference type objects in C# style. More...
 
template<typename T1 , typename T2 >
static std::enable_if<!IsSmartPtr< T1 >::value &&!IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 Compares value type objects in C# style. More...
 
static const TypeInfoType ()
 Impleemnts C# typeof(System.Object) construct. More...
 

Static Public Attributes

static TimeSpan InfiniteMatchTimeout
 Special timeout value to disable match break by timeout. More...
 

Additional Inherited Members

- Public Types inherited from System::Object
typedef SmartPtr< Objectptr
 Alias for smart pointer type. More...
 
typedef System::Details::SharedMembersType shared_members_type
 structure to keep list of shared pointers contained in object. More...
 

Detailed Description

Regular expression that follows C#-like syntax. Objects of this class should only be allocated using System::MakeObject() function. Never create instance of this type on stack or using operator new, as it will result in runtime errors and/or assertion faults. Always wrap this class into System::SmartPtr pointer and use this pointer to pass it to functions as argument.

Constructor & Destructor Documentation

◆ Regex() [1/4]

System::Text::RegularExpressions::Regex::Regex ( )

Constructs empty regexp.

◆ Regex() [2/4]

System::Text::RegularExpressions::Regex::Regex ( const String pattern)

Constructor.

Parameters
patternC#-syntaxed pattern.

◆ Regex() [3/4]

System::Text::RegularExpressions::Regex::Regex ( const String pattern,
RegexOptions  options 
)

Constructor.

Parameters
patternC#-syntaxed pattern.
optionsRegex matching options.

◆ Regex() [4/4]

System::Text::RegularExpressions::Regex::Regex ( const String pattern,
RegexOptions  options,
TimeSpan  matchTimeout 
)

Constructor.

Parameters
patternC#-syntaxed pattern.
optionsRegex matching options.
matchTimeoutTimeout to break matching.

◆ ~Regex()

virtual System::Text::RegularExpressions::Regex::~Regex ( )
virtual

Destructor.

Member Function Documentation

◆ Escape()

static String System::Text::RegularExpressions::Regex::Escape ( const String str)
static

Escapes special characters to use string as part of the pattern.

Parameters
strString to escape special characters in.
Returns
String with escaped special characters.

◆ get_MatchTimeout()

TimeSpan System::Text::RegularExpressions::Regex::get_MatchTimeout ( )
inline

Gets matching timeout.

Returns
Matching timeout set to regex.

◆ get_Options()

RegexOptions System::Text::RegularExpressions::Regex::get_Options ( )
inline

Gets regex options.

Returns
Options regex is created with.

◆ get_RightToLeft()

bool System::Text::RegularExpressions::Regex::get_RightToLeft ( )
inline

Checks if matching is done in right-to-left mode.

Returns
True if matching is done right-to-left, false if it is done left-to-right.

◆ IsMatch() [1/2]

bool System::Text::RegularExpressions::Regex::IsMatch ( const String input,
int  startat = 0 
)

Matches regex against string.

Parameters
inputTarget string.
startatBeginning index.
Returns
True if string matches regex, false otherwise.

◆ IsMatch() [2/2]

static bool System::Text::RegularExpressions::Regex::IsMatch ( const String input,
const String pattern,
RegexOptions  options = RegexOptions::None,
TimeSpan  matchTimeout = InfiniteMatchTimeout,
int  startat = 0 
)
static

Checks if string matches pattern.

Parameters
inputInput string.
patternRegexp pattern.
optionsMatching options.
matchTimeoutTimeout.
startatMatch beginning position.
Returns
True if match is found, false otherwise.

◆ Match() [1/3]

MatchPtr System::Text::RegularExpressions::Regex::Match ( const String input)

Matches regex against string.

Parameters
inputTarget string.
Returns
Match value containing match status and submatches.

◆ Match() [2/3]

MatchPtr System::Text::RegularExpressions::Regex::Match ( const String input,
int  startat,
int  length = 0 
)

Matches regex against string.

Parameters
inputTarget string.
startatBeginning index.
lengthNumber of characters to look through (0 to look through the whole string).
Returns
Match value containing match status and submatches.

◆ Match() [3/3]

static MatchPtr System::Text::RegularExpressions::Regex::Match ( const String input,
const String pattern,
RegexOptions  options = RegexOptions::None,
TimeSpan  matchTimeout = InfiniteMatchTimeout,
int  startat = 0,
int  length = 0 
)
static

Matches string and pattern.

Parameters
inputInput string.
patternRegexp pattern.
optionsMatching options.
matchTimeoutTimeout.
startatMatch beginning position.
lengthNumber of characters to look through (0 diables limit).
Returns
First match found.

◆ Matches() [1/2]

MatchCollectionPtr System::Text::RegularExpressions::Regex::Matches ( const String input,
int  startat = 0 
)

Gets all matches of regex in given string by matching repeatedly.

Parameters
inputInput string.
startatIndex to start matching at.
Returns
Collection of all matches found.

◆ Matches() [2/2]

static MatchCollectionPtr System::Text::RegularExpressions::Regex::Matches ( const String input,
const String pattern,
RegexOptions  options = RegexOptions::None,
TimeSpan  matchTimeout = InfiniteMatchTimeout,
int  startat = 0,
int  length = 0 
)
static

Gets all matches between string and pattern.

Parameters
inputInput string.
patternRegexp pattern.
optionsMatching options.
matchTimeoutTimeout.
startatMatch beginning position.
lengthNumber of characters to look through (0 diables limit).
Returns
All matches found by matching repeatedly.

◆ Replace() [1/11]

String System::Text::RegularExpressions::Regex::Replace ( const String input,
const String replacement 
)

Replaces all matches of regex in string with replacement string.

Parameters
inputInput string.
replacementReplacement string.
Returns
Input string with all regex matches replaced with replacement string.

◆ Replace() [2/11]

String System::Text::RegularExpressions::Regex::Replace ( const String input,
const char_t *  replacement 
)

Replaces all matches of regex in string with replacement string.

Parameters
inputInput string.
replacementReplacement string.
Returns
Input string with all regex matches replaced with replacement string.

◆ Replace() [3/11]

static String System::Text::RegularExpressions::Regex::Replace ( const String input,
const char_t *  pattern,
const char_t *  replacement 
)
static

Replaces all matches of regex in string with replacement string.

Parameters
inputInput string.
patternRegex pattern.
replacementReplacement string.
Returns
Input string with all regex matches replaced with replacement string.

◆ Replace() [4/11]

static String System::Text::RegularExpressions::Regex::Replace ( const String input,
const String pattern,
const char_t *  replacement 
)
static

Replaces all matches of regex in string with replacement string.

Parameters
inputInput string.
patternRegex pattern.
replacementReplacement string.
Returns
Input string with all regex matches replaced with replacement string.

◆ Replace() [5/11]

String System::Text::RegularExpressions::Regex::Replace ( const String input,
MatchEvaluator  evaluator 
)

Replaces all matches in string with delegate-generated replacement strings.

Parameters
inputInput string.
evaluatorDelegate to generate replacement strings based on matches.
Returns
Input strings with all matches replaced.

◆ Replace() [6/11]

String System::Text::RegularExpressions::Regex::Replace ( const String input,
MatchEvaluator  evaluator,
int  count 
)

Replaces all matches in string with delegate-generated replacement strings.

Parameters
inputInput string.
evaluatorDelegate to generate replacement strings based on matches.
countNumber of replacements limit.
Returns
Input strings with all matches replaced.

◆ Replace() [7/11]

String System::Text::RegularExpressions::Regex::Replace ( const String input,
MatchEvaluator  evaluator,
int  count,
int  startat 
)

Replaces all matches in string with delegate-generated replacement strings.

Parameters
inputInput string.
evaluatorDelegate to generate replacement strings based on matches.
countNumber of replacements limit.
startatIndex in input string to start replacement at.
Returns
Input strings with all matches replaced.

◆ Replace() [8/11]

static String System::Text::RegularExpressions::Regex::Replace ( const String input,
const String pattern,
const String replacement,
RegexOptions  options 
)
static

Replaces all matches of regex in string with replacement string.

Parameters
inputInput string.
patternRegex pattern.
replacementReplacement string.
optionsRegex options.
Returns
Input string with all regex matches replaced with replacement string.

◆ Replace() [9/11]

static String System::Text::RegularExpressions::Regex::Replace ( const String input,
const String replacement,
int  count 
)
static

Replaces substrings in string. Not implemented.

◆ Replace() [10/11]

static String System::Text::RegularExpressions::Regex::Replace ( const String input,
const String pattern,
const String replacement 
)
static

Replaces regex matches.

Parameters
inputInput string.
patternRegexp pattern.
replacementReplacement string.
Returns
String with all matches replaced.

◆ Replace() [11/11]

static String System::Text::RegularExpressions::Regex::Replace ( const String input,
const String pattern,
MatchEvaluator  evaluator 
)
static

Replaces regex matches.

Parameters
inputInput string.
patternRegexp pattern.
evaluatorDelegate to generate replacement string for each match.
Returns
String with all matches replaced.

◆ Split() [1/4]

ArrayPtr<String> System::Text::RegularExpressions::Regex::Split ( const String input)

Splits string by regex matches.

Parameters
inputString to split.
Returns
Array of substrings between matches.

◆ Split() [2/4]

ArrayPtr<String> System::Text::RegularExpressions::Regex::Split ( const String input,
int  count 
)

Splits string by regex matches.

Parameters
inputString to split.
countNumber of substrings limit.
Returns
Array of substrings between matches.

◆ Split() [3/4]

static ArrayPtr<String> System::Text::RegularExpressions::Regex::Split ( const String input,
const String pattern,
RegexOptions  options = RegexOptions::None,
TimeSpan  matchTimeout = InfiniteMatchTimeout 
)
static

Splits string by regexp.

Parameters
inputInput string.
patternRegexp pattern.
optionsMatching options.
matchTimeoutTimeout.
Returns
Array of strings between matchse.

◆ Split() [4/4]

static ArrayPtr<String> System::Text::RegularExpressions::Regex::Split ( const String input,
const String pattern,
int  count,
RegexOptions  options = RegexOptions::None,
TimeSpan  matchTimeout = InfiniteMatchTimeout 
)
static

Splits string by regexp.

Parameters
inputInput string.
patternRegexp pattern.
countMatch number limit.
optionsMatching options.
matchTimeoutTimeout.
Returns
Array of strings between matchse.

◆ ToString()

String System::Text::RegularExpressions::Regex::ToString ( )
inlineoverridevirtual

Converts regex to string.

Returns
Regex pattern.

Reimplemented from System::Object.

◆ Unescape()

static String System::Text::RegularExpressions::Regex::Unescape ( const String str)
static

Unescapes special characters in string used as part of the pattern.

Parameters
strString to unescape special characters in.
Returns
String with unescaped special characters.

Member Data Documentation

◆ InfiniteMatchTimeout

TimeSpan System::Text::RegularExpressions::Regex::InfiniteMatchTimeout
static

Special timeout value to disable match break by timeout.