wxRegEx

From WxWiki
Revision as of 19:36, 19 October 2018 by Tierra (talk | contribs) (Text replacement - "<source>" to "<syntaxhighlight lang="cpp">")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Official Classes SmallBlocks.png Archive Containers Controls Data Structures Database Date & Time Debug Device Contexts Dialogs Document & Views Drag & Drop Events Filesystem Frames Graphics Grid Cell Help HTML Logging Miscellaneous Networking Printing Sizers Streams Threading Windows

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.

Example

Read the docs for wxRE_NEWLINE and wxRE_ADVANCED.

Remember you need to escape the backslash ('\') for strings, so you need to 'wxRegEx re("\\s", wxRE_ADVANCED)' for example

    wxString getExpresion( wxString &texto, wxString exp )
    {
        wxString result;
        wxRegEx expresion( exp  , wxRE_ADVANCED + wxRE_ICASE );//wxRE_ICASE | wxRE_DEFAULT
    
        if( expresion.IsValid() )
        {        
            if( expresion.Matches( texto ) )
            {
                result = expresion.GetMatch( texto, 1 );
            }
        }
        return result;
    }

call:

    getExpresion( htmldata, "(?w)href=\"([^\"]*)" );

See Also