2

i am writing an robots.txt parser in c++

 boost::regex exrp( "^User-agent:\s*(.*)"); boost:: match_results<string::const_iterator> what; if(boost::regex_search( robots, what, exrp ) ) { string s( what[1].first, what[1].second ); cout<< s; } 

this should match the useragent with name * but it it returns all datas

0

2 Answers 2

4

You need the double backslash '\\' if you don't use c++0x raw strings.

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

Comments

2

If you want it to match only User-agent: * and not also (e.g.) User-agent: webcrawler you need

"^User-agent:\\s*\\*" 

The * character has a special meaning, so must be escaped with \. The (.*) in your code matches zero or more occurrences of any character and captures the match.

Edit: You also need to escape the backslashes as pointed out by rubber boots.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.