VerbalExpressions is a C++11 Header library that helps to construct difficult regular expressions.
This C++ lib is based off of the (original) Javascript VerbalExpressions library by jehna.
You can see an up to date list of all ports in our organization.
C++11 support for regex is still poor in the standard library, you will likely need boost_regex. Download / set that up, then try the example file. Once C++ standard supports decently it will be painless to switch.
Here's a couple of simple examples to give an idea of how VerbalExpressions works:
// Create an example of how to test for correctly formed URLs
VerEx expr = VerEx()
.searchOneLine()
.startOfLine()
.then( "http" )
.maybe( "s" )
.then( "://" )
.maybe( "www." )
.anythingBut( " " )
.endOfLine();
// Use VerEx's test() function to find if it matches
std::cout << expr.test("https://www.google.com") << std::endl;
// Ouputs the actual expression used: ^(?:http)(?:s)?(?:://)(?:www.)?(?:[^ ]*)$
std::cout << expr << std::endl;
// Create a test string
std::string replaceMe = "Replace bird with a duck";
// Create an expression that seeks for word "bird"
VerEx expr2 = VerEx().find("bird");
// Execute the expression
std::cout << expr2.replace(replaceMe, "duck") << std::endl;
std::cout << VerEx().find( "red" ).replace( "We have a red house", "blue" ) << std::endl;
Here you can find the API documentation for Verbal Expressions
Basic usage of Verbal Expressions is through a singleton, called VerEx()
, that creates a new expression for you:
auto expr = VerEx();
##API
- .anything()
- .anythingBut( const std::string & value )
- .something()
- .somethingBut(const std::string & value)
- .endOfLine()
- .find( const std::string & value )
- .maybe( const std::string & value )
- .startOfLine()
- .then( const std::string & value )
- .any( const std::string & value )
- .anyOf( const std::string & value )
- .br()
- .lineBreak()
- .range( const std::initializer_liststd::string & args )
- .tab()
- .word()
- .withAnyCase()
- .searchOneLine()
- .searchGlobal()
- .replace( const std::string & source, const std::string & value )
- .test()
- .add( expression )
- .multiple( const std::string & value )
- .alt()