0

I am trying to store a regular expression within a variable, i.e if we had a regular expression, \\d and a string, std::string str; then I would store the regular expression \\d within std::string str. From that I could then use str whenever I wanted to use that regular expression.

I tried something like this:

Boost::regex const string_matcher("\\d");
std::string str = string_matcher;

However I realized that it would not work. Does anyone have any ides of how I can store a regular expression?

2
  • Sorry, I don't get the question. What's wrong with std::string str = "\\d"; Boost::regex string_matcher(str); Commented Jan 2, 2012 at 16:37
  • 6
    You really need a good introductory C++ book. You have the solution to your own problem in the code you posted. Commented Jan 2, 2012 at 16:38

2 Answers 2

3
std::string regex = "\\d";
boost::regex expression(regex);
bool ok = boost::regex_match(testStr, expression);
Sign up to request clarification or add additional context in comments.

2 Comments

I should have thought about this earlier, ok thanks for your help man
i don't see the check symbol unless im overlooking it :/
3

You already have your regular expression stored in a variable. You called it string_matcher.

Comments

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.