0

how can I check if the string is matched with an expression using regex c++ (its for robots.txt parser)

eg:

string will be an url
http://www.google.com/example/e/se/in

/*/e/*

means i need to match with the url if it is present or not ....normal query like /example/ can be matched using substring but ..how can i parse some thing similar to this

3
  • 7
    What have you tried so far? Have you taken a look at any existing C++ regex libraries, e.g. Boost (boost.org/doc/libs/1_46_0/libs/regex)? Commented Feb 22, 2011 at 21:45
  • i tried this ` boost::regex reg("/*/a/*"); bool b1 = boost::regex_search("google.com/asd/a/asd", reg);` but it matches google.com/asd/aa/asd also Commented Feb 22, 2011 at 22:09
  • You seem to be confusing shell globs with regular expressions. * means "match zero or more of the preceding", not "match any string" like it does with globs. Change * to .* in both instances. Commented Feb 22, 2011 at 22:34

1 Answer 1

3

Regexes have no language support in the current C++ standard. You'll have to use a 3rd-party library such as Boost.Regex or PCRE.

The upcoming C++0x language standard does provide regexes in the <regex> header file, but the standard has not been finalized, and compiler support for the draft standard is limited. Unless you're already developing code for the C++0x draft, I'd advise against this option to ensure that your code is portable.

Sign up to request clarification or add additional context in comments.

1 Comment

This is incorrect with C++0x. <regex> has been implemented fully in VC++ 2010 and partially in GCC.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.