ICU 78.1 78.1 |
ClassRegexPattern represents a compiled regular expression.More...
#include <regex.h>

Public Member Functions | |
| RegexPattern () | |
| default constructor.More... | |
| RegexPattern (constRegexPattern &source) | |
| Copy Constructor.More... | |
| virtual | ~RegexPattern () |
| Destructor.More... | |
| bool | operator== (constRegexPattern &that) const |
| Comparison operator.More... | |
| bool | operator!= (constRegexPattern &that) const |
| Comparison operator.More... | |
| RegexPattern & | operator= (constRegexPattern &source) |
| Assignment operator.More... | |
| RegexPattern * | clone () const |
| Create an exact copy of thisRegexPattern object.More... | |
| uint32_t | flags () const |
| Get theURegexpFlag match mode flags that were used when compiling this pattern.More... | |
| RegexMatcher * | matcher (constUnicodeString &input,UErrorCode &status) const |
| Creates aRegexMatcher that will match the given input against this pattern.More... | |
| RegexMatcher * | matcher (UErrorCode &status) const |
| Creates aRegexMatcher that will match against this pattern.More... | |
| UnicodeString | pattern () const |
| Returns the regular expression from which this pattern was compiled.More... | |
| UText * | patternText (UErrorCode &status) const |
| Returns the regular expression from which this pattern was compiled.More... | |
| int32_t | groupNumberFromName (constUnicodeString &groupName,UErrorCode &status) const |
| Get the group number corresponding to a named capture group.More... | |
| int32_t | groupNumberFromName (const char *groupName, int32_t nameLength,UErrorCode &status) const |
| Get the group number corresponding to a named capture group.More... | |
| int32_t | split (constUnicodeString &input,UnicodeString dest[], int32_t destCapacity,UErrorCode &status) const |
| Split a string into fields.More... | |
| int32_t | split (UText *input,UText *dest[], int32_t destCapacity,UErrorCode &status) const |
| Split a string into fields.More... | |
| virtualUClassID | getDynamicClassID () const override |
| ICU "poor man's RTTI", returns a UClassID for the actual class.More... | |
| void | dumpPattern () const |
| Dump a compiled pattern.More... | |
Public Member Functions inherited fromicu::UObject | |
| virtual | ~UObject () |
| Destructor.More... | |
Static Public Member Functions | |
| staticRegexPattern * | compile (constUnicodeString ®ex,UParseError &pe,UErrorCode &status) |
| Compiles the regular expression in string form into aRegexPattern object.More... | |
| staticRegexPattern * | compile (UText *regex,UParseError &pe,UErrorCode &status) |
| Compiles the regular expression in string form into aRegexPattern object.More... | |
| staticRegexPattern * | compile (constUnicodeString ®ex, uint32_tflags,UParseError &pe,UErrorCode &status) |
| Compiles the regular expression in string form into aRegexPattern object using the specifiedURegexpFlag match mode flags.More... | |
| staticRegexPattern * | compile (UText *regex, uint32_tflags,UParseError &pe,UErrorCode &status) |
| Compiles the regular expression in string form into aRegexPattern object using the specifiedURegexpFlag match mode flags.More... | |
| staticRegexPattern * | compile (constUnicodeString ®ex, uint32_tflags,UErrorCode &status) |
| Compiles the regular expression in string form into aRegexPattern object using the specifiedURegexpFlag match mode flags.More... | |
| staticRegexPattern * | compile (UText *regex, uint32_tflags,UErrorCode &status) |
| Compiles the regular expression in string form into aRegexPattern object using the specifiedURegexpFlag match mode flags.More... | |
| staticUBool | matches (constUnicodeString ®ex, constUnicodeString &input,UParseError &pe,UErrorCode &status) |
| Test whether a string matches a regular expression.More... | |
| staticUBool | matches (UText *regex,UText *input,UParseError &pe,UErrorCode &status) |
| Test whether a string matches a regular expression.More... | |
| staticUClassID | getStaticClassID () |
| ICU "poor man's RTTI", returns a UClassID for this class.More... | |
Friends | |
| class | RegexCompile |
| class | RegexMatcher |
| class | RegexCImpl |
ClassRegexPattern represents a compiled regular expression.
It includes factory methods for creating aRegexPattern object from the source (string) form of a regular expression, methods for creating RegexMatchers that allow the pattern to be applied to input text, and a few convenience methods for simple common uses of regular expressions.
ClassRegexPattern is not intended to be subclassed.
| icu::RegexPattern::RegexPattern | ( | ) |
default constructor.
Create aRegexPattern object that refers to no actual pattern. Not normally needed;RegexPattern objects are usually created using the factory methodcompile().
| icu::RegexPattern::RegexPattern | ( | constRegexPattern & | source | ) |
Copy Constructor.
Create a newRegexPattern object that is equivalent to the source object.
| source | the pattern object to be copied. |
| virtual |
Destructor.
Note that aRegexPattern object must persist so long as anyRegexMatcher objects that were created from theRegexPattern are active.
| RegexPattern* icu::RegexPattern::clone | ( | ) | const |
Create an exact copy of thisRegexPattern object.
SinceRegexPattern is not intended to be subclassed,clone() and the copy construction are equivalent operations.
| static |
Compiles the regular expression in string form into aRegexPattern object using the specifiedURegexpFlag match mode flags.
These compile methods, rather than the constructors, are the usual way thatRegexPattern objects are created.
Note thatRegexPattern objects must not be deleted whileRegexMatcher objects created from the pattern are active. RegexMatchers keep a pointer back to their pattern, so premature deletion of the pattern is a catastrophic error.
Note that it is often more convenient to construct aRegexMatcher directly from a pattern string instead of than separately compiling the pattern and then creating aRegexMatcher object from the pattern.
| regex | The regular expression to be compiled. |
| flags | TheURegexpFlag match mode flags to be used, e.g.UREGEX_CASE_INSENSITIVE. |
| status | A reference to a UErrorCode to receive any errors. |
| static |
Compiles the regular expression in string form into aRegexPattern object using the specifiedURegexpFlag match mode flags.
These compile methods, rather than the constructors, are the usual way thatRegexPattern objects are created.
Note thatRegexPattern objects must not be deleted whileRegexMatcher objects created from the pattern are active. RegexMatchers keep a pointer back to their pattern, so premature deletion of the pattern is a catastrophic error.
Note that it is often more convenient to construct aRegexMatcher directly from a pattern string instead of than separately compiling the pattern and then creating aRegexMatcher object from the pattern.
| regex | The regular expression to be compiled. |
| flags | TheURegexpFlag match mode flags to be used, e.g.UREGEX_CASE_INSENSITIVE. |
| pe | Receives the position (line and column numbers) of any error within the regular expression.) |
| status | A reference to a UErrorCode to receive any errors. |
| static |
Compiles the regular expression in string form into aRegexPattern object.
These compile methods, rather than the constructors, are the usual way thatRegexPattern objects are created.
Note thatRegexPattern objects must not be deleted whileRegexMatcher objects created from the pattern are active. RegexMatchers keep a pointer back to their pattern, so premature deletion of the pattern is a catastrophic error.
AllURegexpFlag pattern match mode flags are set to their default values.
Note that it is often more convenient to construct aRegexMatcher directly from a pattern string rather than separately compiling the pattern and then creating aRegexMatcher object from the pattern.
| regex | The regular expression to be compiled. |
| pe | Receives the position (line and column nubers) of any error within the regular expression.) |
| status | A reference to a UErrorCode to receive any errors. |
| static |
Compiles the regular expression in string form into aRegexPattern object using the specifiedURegexpFlag match mode flags.
These compile methods, rather than the constructors, are the usual way thatRegexPattern objects are created.
Note thatRegexPattern objects must not be deleted whileRegexMatcher objects created from the pattern are active. RegexMatchers keep a pointer back to their pattern, so premature deletion of the pattern is a catastrophic error.
Note that it is often more convenient to construct aRegexMatcher directly from a pattern string instead of than separately compiling the pattern and then creating aRegexMatcher object from the pattern.
| regex | The regular expression to be compiled. Note, the text referred to by thisUText must not be deleted during the lifetime of theRegexPattern object or anyRegexMatcher object created from it. |
| flags | TheURegexpFlag match mode flags to be used, e.g.UREGEX_CASE_INSENSITIVE. |
| status | A reference to a UErrorCode to receive any errors. |
| static |
Compiles the regular expression in string form into aRegexPattern object using the specifiedURegexpFlag match mode flags.
These compile methods, rather than the constructors, are the usual way thatRegexPattern objects are created.
Note thatRegexPattern objects must not be deleted whileRegexMatcher objects created from the pattern are active. RegexMatchers keep a pointer back to their pattern, so premature deletion of the pattern is a catastrophic error.
Note that it is often more convenient to construct aRegexMatcher directly from a pattern string instead of than separately compiling the pattern and then creating aRegexMatcher object from the pattern.
| regex | The regular expression to be compiled. Note, the text referred to by thisUText must not be deleted during the lifetime of theRegexPattern object or anyRegexMatcher object created from it. |
| flags | TheURegexpFlag match mode flags to be used, e.g.UREGEX_CASE_INSENSITIVE. |
| pe | Receives the position (line and column numbers) of any error within the regular expression.) |
| status | A reference to a UErrorCode to receive any errors. |
| static |
Compiles the regular expression in string form into aRegexPattern object.
These compile methods, rather than the constructors, are the usual way thatRegexPattern objects are created.
Note thatRegexPattern objects must not be deleted whileRegexMatcher objects created from the pattern are active. RegexMatchers keep a pointer back to their pattern, so premature deletion of the pattern is a catastrophic error.
AllURegexpFlag pattern match mode flags are set to their default values.
Note that it is often more convenient to construct aRegexMatcher directly from a pattern string rather than separately compiling the pattern and then creating aRegexMatcher object from the pattern.
| regex | The regular expression to be compiled. Note, the text referred to by thisUText must not be deleted during the lifetime of theRegexPattern object or anyRegexMatcher object created from it. |
| pe | Receives the position (line and column nubers) of any error within the regular expression.) |
| status | A reference to a UErrorCode to receive any errors. |
| void icu::RegexPattern::dumpPattern | ( | ) | const |
Dump a compiled pattern.
Internal debug function.
| uint32_t icu::RegexPattern::flags | ( | ) | const |
Get theURegexpFlag match mode flags that were used when compiling this pattern.
| overridevirtual |
ICU "poor man's RTTI", returns a UClassID for the actual class.
Reimplemented fromicu::UObject.
| static |
ICU "poor man's RTTI", returns a UClassID for this class.
| int32_t icu::RegexPattern::groupNumberFromName | ( | const char * | groupName, |
| int32_t | nameLength, | ||
| UErrorCode & | status | ||
| ) | const |
Get the group number corresponding to a named capture group.
The returned number can be used with any function that access capture groups by number.
The function returns an error status if the specified name does not appear in the pattern.
| groupName | The capture group name, platform invariant characters only. |
| nameLength | The length of the name, or -1 if the name is nul-terminated. |
| status | A UErrorCode to receive any errors. |
| int32_t icu::RegexPattern::groupNumberFromName | ( | constUnicodeString & | groupName, |
| UErrorCode & | status | ||
| ) | const |
Get the group number corresponding to a named capture group.
The returned number can be used with any function that access capture groups by number.
The function returns an error status if the specified name does not appear in the pattern.
| groupName | The capture group name. |
| status | A UErrorCode to receive any errors. |
| RegexMatcher* icu::RegexPattern::matcher | ( | constUnicodeString & | input, |
| UErrorCode & | status | ||
| ) | const |
Creates aRegexMatcher that will match the given input against this pattern.
TheRegexMatcher can then be used to perform match, find or replace operations on the input. Note that aRegexPattern object must not be deleted while RegexMatchers created from it still exist and might possibly be used again.
The matcher will retain a reference to the supplied input string, and all regexp pattern matching operations happen directly on this original string. It is critical that the string not be altered or deleted before use by the regular expression operations is complete.
| input | The input string to which the regular expression will be applied. |
| status | A reference to a UErrorCode to receive any errors. |
| RegexMatcher* icu::RegexPattern::matcher | ( | UErrorCode & | status | ) | const |
Creates aRegexMatcher that will match against this pattern.
TheRegexMatcher can be used to perform match, find or replace operations. Note that aRegexPattern object must not be deleted while RegexMatchers created from it still exist and might possibly be used again.
| status | A reference to a UErrorCode to receive any errors. |
| static |
Test whether a string matches a regular expression.
This convenience function both compiles the regular expression and applies it in a single operation. Note that if the same pattern needs to be applied repeatedly, this method will be less efficient than creating and reusing aRegexMatcher object.
| regex | The regular expression |
| input | The string data to be matched |
| pe | Receives the position of any syntax errors within the regular expression |
| status | A reference to a UErrorCode to receive any errors. |
| static |
Test whether a string matches a regular expression.
This convenience function both compiles the regular expression and applies it in a single operation. Note that if the same pattern needs to be applied repeatedly, this method will be less efficient than creating and reusing aRegexMatcher object.
| regex | The regular expression |
| input | The string data to be matched |
| pe | Receives the position of any syntax errors within the regular expression |
| status | A reference to a UErrorCode to receive any errors. |
| inline |
Comparison operator.
TwoRegexPattern objects are considered equal if they were constructed from identical source patterns using the sameURegexpFlag settings.
| that | aRegexPattern object to compare with "this". |
Definition at line132 of fileregex.h.
Referencesicu::operator==().
| RegexPattern& icu::RegexPattern::operator= | ( | constRegexPattern & | source | ) |
Assignment operator.
After assignment, thisRegexPattern will behave identically to the source object.
| bool icu::RegexPattern::operator== | ( | constRegexPattern & | that | ) | const |
Comparison operator.
TwoRegexPattern objects are considered equal if they were constructed from identical source patterns using the sameURegexpFlag settings.
| that | aRegexPattern object to compare with "this". |
| UnicodeString icu::RegexPattern::pattern | ( | ) | const |
Returns the regular expression from which this pattern was compiled.
This method will work even if the pattern was compiled from aUText.
Note: If the pattern was originally compiled from aUText, and thatUText was modified, the returned string may no longer reflect theRegexPattern object.
| UText* icu::RegexPattern::patternText | ( | UErrorCode & | status | ) | const |
Returns the regular expression from which this pattern was compiled.
This method will work even if the pattern was compiled from aUnicodeString.
Note: This is the original input, not a clone. If the pattern was originally compiled from aUText, and thatUText was modified, the returnedUText may no longer reflect theRegexPattern object.
| int32_t icu::RegexPattern::split | ( | constUnicodeString & | input, |
| UnicodeString | dest[], | ||
| int32_t | destCapacity, | ||
| UErrorCode & | status | ||
| ) | const |
Split a string into fields.
Somewhat likesplit() from Perl or Java. Pattern matches identify delimiters that separate the input into fields. The input data between the delimiters becomes the fields themselves.
If the delimiter pattern includes capture groups, the captured text will also appear in the destination array of output strings, interspersed with the fields. This is similar to Perl, but differs from Java, which ignores the presence of capture groups in the pattern.
Trailing empty fields will always be returned, assuming sufficient destination capacity. This differs from the default behavior for Java and Perl where trailing empty fields are not returned.
The number of strings produced by the split operation is returned. This count includes the strings from capture groups in the delimiter pattern. This behavior differs from Java, which ignores capture groups.
For the best performance onsplit() operations,RegexMatcher::split is preferable to this function
| input | The string to be split into fields. The field delimiters match the pattern (in the "this" object) |
| dest | An array of UnicodeStrings to receive the results of the split. This is an array of actualUnicodeString objects, not an array of pointers to strings. Local (stack based) arrays can work well here. |
| destCapacity | The number of elements in the destination array. If the number of fields found is less than destCapacity, the extra strings in the destination array are not altered. If the number of destination strings is less than the number of fields, the trailing part of the input string, including any field delimiters, is placed in the last destination string. |
| status | A reference to a UErrorCode to receive any errors. |
| int32_t icu::RegexPattern::split | ( | UText * | input, |
| UText * | dest[], | ||
| int32_t | destCapacity, | ||
| UErrorCode & | status | ||
| ) | const |
Split a string into fields.
Somewhat like split() from Perl or Java. Pattern matches identify delimiters that separate the input into fields. The input data between the delimiters becomes the fields themselves.
If the delimiter pattern includes capture groups, the captured text will also appear in the destination array of output strings, interspersed with the fields. This is similar to Perl, but differs from Java, which ignores the presence of capture groups in the pattern.
Trailing empty fields will always be returned, assuming sufficient destination capacity. This differs from the default behavior for Java and Perl where trailing empty fields are not returned.
The number of strings produced by the split operation is returned. This count includes the strings from capture groups in the delimiter pattern. This behavior differs from Java, which ignores capture groups.
For the best performance onsplit() operations,RegexMatcher::split() is preferable to this function
| input | The string to be split into fields. The field delimiters match the pattern (in the "this" object) |
| dest | An array of mutableUText structs to receive the results of the split. If a field is nullptr, a newUText is allocated to contain the results for that field. This newUText is not guaranteed to be mutable. |
| destCapacity | The number of elements in the destination array. If the number of fields found is less than destCapacity, the extra strings in the destination array are not altered. If the number of destination strings is less than the number of fields, the trailing part of the input string, including any field delimiters, is placed in the last destination string. |
| status | A reference to a UErrorCode to receive any errors. |