Opened 19 years ago

Closed 19 years ago

#195 closed Support Requests (Invalid)

regex_match problem

Reported by: nobody Owned by: nobody
Milestone: Component: None
Version: None Severity:
Keywords: Cc:

Description

Ruslan Talpa <tristan@pisem.net>
I want to match different strings in a whois result and i 
am having some problems.

first a execut a shell command similar to:
"/usr/bin/whois domain.com > tmp_file"
so after this we have a file, from wich i read line by line 
and try to match some strings but no matter what the 
reg. expression is the regex_match returns false.
i even tried "regex expression("a");" and still no luck
The only thing i can think of is that there is some 
character encoding stuff envolved but i don't know what 
to do. Please help, tell me what i am doin wrong


here are the functions involved
int parse_line(const char*  response)
{
   regex expression("a");
   cmatch what;
   if(regex_match(response, what, expression))
   {
      cout << "MATCH\n";
   }
   else
   {
      cout << "NO MATCH\n";
   }
   return 0;
}


int get_info(string domain, char* pipe_file)
{
        string line;
        Message msg;
        strstream command;
        command << "/usr/bin/whois " << domain.c_str() 
<< " > " << pipe_file;
        system(command.str());
        ifstream f(pipe_file);
        while (!f.eof())
        {
                getline(f, line);
                parse_line(line.c_str());
        }
        f.close();
        return 0;
}


Change History (3)

comment:1 by nobody, 19 years ago

Logged In: NO 

You're using regex_match when you should be using regex_search.  
regex_match requires that the whole of the string matches the regex 
whereas regex_search requires that some part of it matches.

regards
          aitor

comment:2 by bjorn_karlsson, 19 years ago

Logged In: YES 
user_id=536454

The problem is that you're using the wrong algorithm - 
regex_match only returns true on an exact match, i.e. in your 
example, the input string would need to be exactly "a" to be 
a match. What you probably want is to use the algorithm 
regex_search.

By the way, we normally answer this type of questions on the 
Boost-Users mailing list 
(http://groups.yahoo.com/group/Boost-Users/). See the 
Boost homepage (www.boost.org) for more details.

Hope this helps,

Bjorn Karlsson
bjorn_karlsson@acm.org

comment:3 by bjorn_karlsson, 19 years ago

Status: assignedclosed
Note: See TracTickets for help on using tickets.