.\" This is a wxWidgets manpage page generated from the XML docs .TH wxRegEx 3wx 2005-02-15 "wxWidgets" "wxWidgets class documentation" .SH NAME wxRegEx \- Regular expression support .SH DESCRIPTION wxRegEx represents a regular expression. This class provides support for regular expressions matching and also replacement. It is built on top of either the system library (if it has support for POSIX regular expressions - which is the case of the most modern Unices) or uses the built in Henry Spencer's library. Henry Spencer would appreciate being given credit in the documentation of software which uses his library, but that is not a requirement. Regular expressions, as defined by POSIX, come in two flavours: extended and basic . The builtin library also adds a third flavour of expression advanced , which is not available when using the system library. Unicode is fully supported only when using the builtin library. When using the system library in Unicode mode, the expressions and data are translated to the default 8-bit encoding before being passed to the library. On platforms where a system library is available, the default is to use the builtin library for Unicode builds, and the system library otherwise. It is possible to use the other if preferred by selecting it when building the wxWidgets. .SH "PARENTS" .SH "INCLUDE FILES" wx/regex.h .SH MEMBERS .SS wxRegEx () Default ctor: use Compile() later. .SS wxRegEx (const wxString& exprint flags = wxRE_DEFAULT) Create and compile the regular expression, use IsValid to test for compilation errors. .SS ~wxRegEx () dtor not virtual, don't derive from this class .SS bool Compile (const wxString& patternint flags = wxRE_DEFAULT) Compile the string into regular expression, return true if ok or false if string has a syntax error. .SS bool IsValid () Return true if this is a valid compiled regular expression, false otherwise. .SS bool GetMatch (size_t* startsize_t* lensize_t index = 0) Get the start index and the length of the match of the expression (if index is 0) or a bracketed subexpression ( index different from 0). May only be called after successful call to Matches() and only if wxRE_NOSUB was not used in Compile() . Returns false if no match or if an error occurred. .SS wxString GetMatch (const wxString& textsize_t index = 0) Returns the part of string corresponding to the match where index is interpreted as above. Empty string is returned if match failed May only be called after successful call to Matches() and only if wxRE_NOSUB was not used in Compile() . .SS size_t GetMatchCount () Returns the size of the array of matches, i.e. the number of bracketed subexpressions plus one for the expression itself, or 0 on error. May only be called after successful call to Compile() . and only if wxRE_NOSUB was not used. .SS bool Matches (const wxChar* textint flags = 0) Matches the precompiled regular expression against the string text , returns true if matches and false otherwise. Flags may be combination of wxRE_NOTBOL and wxRE_NOTEOL . May only be called after successful call to Compile() . .SS int Replace (wxString* textconst wxString& replacementsize_t maxMatches = 0) Replaces the current regular expression in the string pointed to by text , with the text in replacement and return number of matches replaced (maybe 0 if none found) or -1 on error. The replacement text may contain back references \backslashnumber which will be replaced with the value of the corresponding subexpression in the pattern match. \backslash0 corresponds to the entire match and & is a synonym for it. Backslash may be used to quote itself or & character. maxMatches may be used to limit the number of replacements made, setting it to 1, for example, will only replace first occurrence (if any) of the pattern in the text while default value of 0 means replace all. .SS int ReplaceAll (wxString* textconst wxString& replacement) Replace all occurrences: this is actually a synonym for Replace() . .SS int ReplaceFirst (wxString* textconst wxString& replacement) Replace the first occurrence. .SH EXAMPLE A bad example of processing some text containing email addresses (the example is bad because the real email addresses can have more complicated form than user@host.net ): wxString text; ... wxRegEx reEmail = wxT("([^@]+)@([[:alnum:].-_].)+([[:alnum:]]+)"); if ( reEmail.Matches(text) ) { wxString text = reEmail.GetMatch(email); wxString username = reEmail.GetMatch(email, 1); if ( reEmail.GetMatch(email, 3) == wxT("com") ) // .com TLD? { ... } } // or we could do this to hide the email address size_t count = reEmail.ReplaceAll(text, wxT("HIDDEN@\\2\\3")); printf("text now contains .SH "SEE ALSO" .SH "AUTHORS" Documentation content by Julian Smart, Robert Roebling, Vadim Zeitlin, Robin Dunn, et al Conversion to manpage format by Arnout Engelen (http://bzzt.net), bugreports welcome.