Case Sensitive Partial Match with Boost's Regex

Dear all,

From the following code, I expect to get this output from the corresponding input:

1
2
3
4
5
  
    Input: FOO     Output: Match
    Input: FOOBAR  Output: Match
    Input: BAR     Output: No Match
    Input: fOOBar  Output: No Match


But why it gives "No Match" for input FOOBAR?



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
    #include <iostream>
    #include <vector>
    #include <fstream>
    #include <sstream>
    #include <boost/regex.hpp>
    using namespace std;
    using namespace boost;
    
    
    int main  ( int arg_count, char *arg_vec[] ) {
       if (arg_count !=2 ) {
           cerr << "expected one argument" << endl;
           return EXIT_FAILURE;
       }
    
       string InputString = arg_vec[1];
       string toMatch = "FOO";
    
       const regex e(toMatch);
       if (regex_match(InputString, e,match_partial)) {
           cout << "Match" << endl;
       } else {
           cout << "No Match" << endl;
       }
    
    
       return 0;
    }


Compiled with this command:
g++ -I ~/.boost/include/boost-1_37 test.cc -o test /home/gundalav/.boost/lib/libboost_regex-gcc33-mt-1_37.a
Last edited on
use regex_search() instead.
Topic archived. No new replies allowed.