user1056635
user1056635

Reputation: 795

How can make a regex using boost in c++?

I need to create a regex that do the matching of 2 chars: & OR |.

The line of code is like this:

boost::regex EXPR( "[0-9][0-9][A-Za-z]" ) ;

If I type any string, I would see if the chars listed above are contained in it. How is possible to do this?

Upvotes: 0

Views: 153

Answers (3)

Geom
Geom

Reputation: 57

This should work: ".*?\Q|\E.*". Note that you need to double the backslashes, so it is:

string yourCharacter("|"); // or "&"
string rex(".*?\\Q"+yourCharacter+"\\E.*");

(all characters before and after are matched by this regex)

Here is an online tool to test regular expressions: http://gskinner.com/RegExr/

Upvotes: 0

MSalters
MSalters

Reputation: 179917

Based on my interpretation of the grammar: [0-9A-Za-z]*[|&][0-9A-Za-z|&]*

Upvotes: 1

Merlyn Morgan-Graham
Merlyn Morgan-Graham

Reputation: 59111

I wouldn't write a regular expression to match the characters & or |.

I'd use std::string::find - http://www.cplusplus.com/reference/string/string/find/

Upvotes: 4

Related Questions