Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expressions

Status
Not open for further replies.

jimberger

Programmer
Jul 5, 2001
222
GB
Hello,

Does anybody know how i do regular expressions in c++?

do i need to include a library?

could someone provide me with a short example?

i am familar with regular expressions, its more how i go about using them in c++ is what i'm after.

cheers


 
If you can work under non Windows OS you can get for free the Qt library, it provides good support for pattern matching with regular expressions.
Under Windows you must pay a license fee.

Look at the class QRegExp, or the online documentation, especially the "Detailed description" part :

--
Globos
 
Use ATL regular expressions:
Code:
//C++ Widnows
#include <atlrx.h>
int main(int argc, char* argv[])
{
   CAtlRegExp<> reUrl;
   // five match groups: scheme, authority, path, query, fragment
   REParseError status = reUrl.Parse("({[^:/?#]+}:)?(//{[^/?#]*})?{[^?#]*}(?{[^#]*})?(#{.*})?" );
   if (REPARSE_ERROR_OK != status)return 0;//unepected error
   CAtlREMatchContext<> mcUrl;
   if (!reUrl.Match("[URL unfurl="true"]http://search.microsoft.com/us/Search.asp?qu=atl&boolean=ALL#results",[/URL] &mcUrl))
   {
      // Unexpected error.
      return 0;
   }
   for (UINT nGroupIndex = 0; nGroupIndex < mcUrl.m_uNumGroups; ++nGroupIndex)
   {
      const CAtlREMatchContext<>::RECHAR* szStart = 0;
      const CAtlREMatchContext<>::RECHAR* szEnd = 0;
      mcUrl.GetMatch(nGroupIndex, &szStart, &szEnd);
      ptrdiff_t nLength = szEnd - szStart;
      printf("%d: \"%.*s\"\n", nGroupIndex, nLength, szStart);
   }
}

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top