1

It is obvious that here must me match, but this code stills returns false.

#include <iostream>
#include <boost/regex.hpp>
using namespace std;
using namespace boost;

int main() {
  cout << regex_match("some text", regex("text")) << endl;
}
rsk82
  • 28,217
  • 50
  • 150
  • 240
  • 2
    I don't know this `regex_match` function, but it possibly *auto-anchors* the pattern with `^` and `$`. Try with `.*text`. – sp00m Jan 29 '13 at 22:30
  • @sp00m Yes, replacing `regex("text")` by `regex(".*text")` would match as well, as it covers the complete input `"some text"`. (`regex_search` is the simple way, however.) – Philipp Claßen Jan 29 '13 at 22:42

1 Answers1

4

regex_match must match all of the given character sequence. Try regex_search instead.

Philipp Claßen
  • 41,306
  • 31
  • 146
  • 239
  • 1
    thanks, http://stackoverflow.com/questions/11628047/difference-between-regex-match-and-regex-search – rsk82 Jan 29 '13 at 22:34