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

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. More...

Inherits System::Object.

Public Member Functions

ASPOSECPP_SHARED_API Regex ()
 Constructs empty regexp. More...
 
ASPOSECPP_SHARED_API Regex (const String &pattern)
 Constructor. More...
 
ASPOSECPP_SHARED_API Regex (const String &pattern, RegexOptions options)
 Constructor. More...
 
ASPOSECPP_SHARED_API Regex (const String &pattern, RegexOptions options, TimeSpan matchTimeout)
 Constructor. More...
 
TimeSpan get_MatchTimeout ()
 Gets matching timeout. More...
 
RegexOptions get_Options ()
 Gets regex options. More...
 
bool get_RightToLeft ()
 Checks if matching is done in right-to-left mode. More...
 
ASPOSECPP_SHARED_API bool IsMatch (const String &input, int startat=0)
 Matches regex against string. More...
 
ASPOSECPP_SHARED_API MatchPtr Match (const String &input)
 Matches regex against string. More...
 
ASPOSECPP_SHARED_API MatchPtr Match (const String &input, int startat, int length=0)
 Matches regex against string. More...
 
ASPOSECPP_SHARED_API MatchCollectionPtr Matches (const String &input, int startat=0)
 Gets all matches of regex in given string by matching repeatedly. More...
 
ASPOSECPP_SHARED_API String Replace (const String &input, const String &replacement)
 Replaces all matches of regex in string with replacement string. More...
 
ASPOSECPP_SHARED_API String Replace (const String &input, const char_t *replacement)
 Replaces all matches of regex in string with replacement string. More...
 
ASPOSECPP_SHARED_API String Replace (const String &input, MatchEvaluator evaluator)
 Replaces all matches in string with delegate-generated replacement strings. More...
 
ASPOSECPP_SHARED_API String Replace (const String &input, MatchEvaluator evaluator, int count)
 Replaces all matches in string with delegate-generated replacement strings. More...
 
ASPOSECPP_SHARED_API String Replace (const String &input, MatchEvaluator evaluator, int count, int startat)
 Replaces all matches in string with delegate-generated replacement strings. More...
 
ASPOSECPP_SHARED_API ArrayPtr< StringSplit (const String &input)
 Splits string by regex matches. More...
 
ASPOSECPP_SHARED_API ArrayPtr< StringSplit (const String &input, int count)
 Splits string by regex matches. More...
 
ASPOSECPP_SHARED_API ArrayPtr< StringSplit (const String &input, int count, int startat)
 Splits an input string a specified maximum number of times into an array of substrings, 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. More...
 
String ToString () const override
 Converts regex to string. More...
 
- Public Member Functions inherited from System::Object
ASPOSECPP_SHARED_API Object ()
 Creates object. Initializes all internal data structures. More...
 
virtual ASPOSECPP_SHARED_API ~Object ()
 Destroys object. Frees all internal data structures. More...
 
ASPOSECPP_SHARED_API 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...
 
ASPOSECPP_SHARED_API void Lock ()
 Implements C# lock() statement locking. Call directly or use LockContext sentry object. More...
 
ASPOSECPP_SHARED_API void Unlock ()
 Implements C# lock() statement unlocking. Call directly or use LockContext sentry object. More...
 
virtual ASPOSECPP_SHARED_API bool Equals (ptr obj)
 Compares objects using C# Object.Equals semantics. More...
 
virtual ASPOSECPP_SHARED_API int GetHashCode () const
 Analog of C# Object.GetHashCode() method. Enables hashing of custom objects. More...
 
virtual ASPOSECPP_SHARED_API ptr MemberwiseClone () const
 Analog of C# Object.MemberwiseClone() method. Enables cloning custom types. More...
 
virtual ASPOSECPP_SHARED_API const TypeInfoGetType () const
 Gets actual type of object. Analog of C# System.Object.GetType() call. More...
 
virtual ASPOSECPP_SHARED_API bool Is (const TypeInfo &targetType) const
 Check if object represents an instance of type described by targetType. Analog of C# 'is' operator. More...
 
virtual ASPOSECPP_SHARED_API 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 ReferenceEquals (String const &str, std::nullptr_t)
 Specialization of Object::ReferenceEquals for case of string and nullptr. More...
 
template<>
bool ReferenceEquals (String const &str1, String const &str2)
 Specialization of Object::ReferenceEquals for case of strings. More...
 

Static Public Member Functions

static ASPOSECPP_SHARED_API String Replace (const String &input, const char_t *pattern, const char_t *replacement)
 Replaces all matches of regex in string with replacement string. More...
 
static ASPOSECPP_SHARED_API String Replace (const String &input, const String &pattern, const char_t *replacement)
 Replaces all matches of regex in string with replacement string. More...
 
static ASPOSECPP_SHARED_API String Replace (const String &input, const String &pattern, MatchEvaluator evaluator, RegexOptions options)
 Replaces all matches in string with delegate-generated replacement strings (static function). More...
 
static ASPOSECPP_SHARED_API String Replace (const String &input, const String &pattern, const String &replacement, RegexOptions options)
 Replaces all matches of regex in string with replacement string. More...
 
static ASPOSECPP_SHARED_API String Replace (const String &input, const String &replacement, int count)
 Replaces substrings in string. Not implemented. More...
 
static ASPOSECPP_SHARED_API String Replace (const String &input, const String &replacement, int count, int startat)
 Replaces substrings in string. Not implemented. More...
 
static ASPOSECPP_SHARED_API bool IsMatch (const String &input, const String &pattern, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout, int startat=0)
 Checks if string matches pattern. More...
 
static ASPOSECPP_SHARED_API MatchPtr Match (const String &input, const String &pattern, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout, int startat=0, int length=0)
 Matches string and pattern. More...
 
static ASPOSECPP_SHARED_API MatchCollectionPtr Matches (const String &input, const String &pattern, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout, int startat=0, int length=0)
 Gets all matches between string and pattern. More...
 
static ASPOSECPP_SHARED_API String Replace (const String &input, const String &pattern, const String &replacement)
 Replaces regex matches. More...
 
static ASPOSECPP_SHARED_API String Replace (const String &input, const String &pattern, MatchEvaluator evaluator)
 Replaces regex matches. More...
 
static ASPOSECPP_SHARED_API ArrayPtr< StringSplit (const String &input, const String &pattern, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout)
 Splits string by regexp. More...
 
static ASPOSECPP_SHARED_API ArrayPtr< StringSplit (const String &input, const String &pattern, int count, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout)
 Splits string by regexp. More...
 
static ASPOSECPP_SHARED_API String Escape (const String &str)
 Escapes special characters to use string as part of the pattern. More...
 
static ASPOSECPP_SHARED_API String Unescape (const String &str)
 Unescapes special characters in string used as part of the pattern. More...
 
- 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...
 
template<>
bool Equals (float const &objA, float const &objB)
 Emulates C#-style floating point comparison where two NaNs are considered equal even though according to IEC 60559:1989 NaN is not equal to any value, including NaN. More...
 
template<>
bool Equals (double const &objA, double const &objB)
 Emulates C#-style floating point comparison where two NaNs are considered equal even though according to IEC 60559:1989 NaN is not equal to any value, including NaN. More...
 

Static Public Attributes

static TimeSpan ASPOSECPP_SHARED_API 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]

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

Constructs empty regexp.

◆ Regex() [2/4]

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

Constructor.

Parameters
patternC#-syntaxed pattern.

◆ Regex() [3/4]

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

Constructor.

Parameters
patternC#-syntaxed pattern.
optionsRegex matching options.

◆ Regex() [4/4]

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

Constructor.

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

Member Function Documentation

◆ Escape()

static ASPOSECPP_SHARED_API 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]

static ASPOSECPP_SHARED_API 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.

◆ IsMatch() [2/2]

ASPOSECPP_SHARED_API 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.

◆ Match() [1/3]

ASPOSECPP_SHARED_API 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]

static ASPOSECPP_SHARED_API 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.

◆ Match() [3/3]

ASPOSECPP_SHARED_API 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.

◆ Matches() [1/2]

static ASPOSECPP_SHARED_API 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.

◆ Matches() [2/2]

ASPOSECPP_SHARED_API 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.

◆ Replace() [1/13]

static ASPOSECPP_SHARED_API 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() [2/13]

ASPOSECPP_SHARED_API 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/13]

static ASPOSECPP_SHARED_API 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() [4/13]

static ASPOSECPP_SHARED_API 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() [5/13]

static ASPOSECPP_SHARED_API 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() [6/13]

static ASPOSECPP_SHARED_API 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.

◆ Replace() [7/13]

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

Replaces all matches in string with delegate-generated replacement strings (static function).

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

◆ Replace() [8/13]

ASPOSECPP_SHARED_API 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() [9/13]

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

Replaces substrings in string. Not implemented.

◆ Replace() [10/13]

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

Replaces substrings in string. Not implemented.

◆ Replace() [11/13]

ASPOSECPP_SHARED_API 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() [12/13]

ASPOSECPP_SHARED_API 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() [13/13]

ASPOSECPP_SHARED_API 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.

◆ Split() [1/5]

ASPOSECPP_SHARED_API 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/5]

static ASPOSECPP_SHARED_API 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.

◆ Split() [3/5]

static ASPOSECPP_SHARED_API 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/5]

ASPOSECPP_SHARED_API 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() [5/5]

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

Splits an input string a specified maximum number of times into an array of substrings, 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.

Parameters
inputThe string to be split.
countThe maximum number of times the split can occur.
startatThe character position in the input string where the search will begin.
Returns
An array of strings.

◆ ToString()

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

Converts regex to string.

Returns
Regex pattern.

Reimplemented from System::Object.

◆ Unescape()

static ASPOSECPP_SHARED_API 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 ASPOSECPP_SHARED_API System::Text::RegularExpressions::Regex::InfiniteMatchTimeout
static

Special timeout value to disable match break by timeout.