CppVerbalExpressions

C++ regular expressions made easy

  • Owner: VerbalExpressions/CppVerbalExpressions
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

CppVerbalExpressions

C++ Regular Expressions made easy

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.

Other Implementations

You can see an up to date list of all ports on VerbalExpressions.github.io.

How to get started

In case you do not have C++11 compliant standard library you can still use boost.regex.

Examples

Here's a couple of simple examples to give an idea of how VerbalExpressions works:

Testing if we have a valid URL

// Create an example of how to test for correctly formed URLs
verex expr = verex()
            .search_one_line()
            .start_of_line()
            .then( "http" )
            .maybe( "s" )
            .then( "://" )
            .maybe( "www." )
            .anything_but( " " )
            .end_of_line();

// 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;

Replacing strings

// 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;

Shorthand for string replace:

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

Basic usage of Verbal Expressions starts from the expression verex(). You can chain methods afterwards. Those are described under the "terms" section.

auto expr = verex();

API

Terms

  • .anything()
  • .anything_but( const std::string & value )
  • .something()
  • .something_but(const std::string & value)
  • .end_of_line()
  • .find( const std::string & value )
  • .maybe( const std::string & value )
  • .start_of_line()
  • .then( const std::string & value )

Special characters and groups

  • .any( const std::string & value )
  • .any_of( const std::string & value )
  • .br()
  • .linebreak()
  • .range( const std::vector<std::pair<std::string, std::string>> & args )
  • .range( const std::std::string & a, const & std::string b )
  • .tab()
  • .word()

Modifiers

  • .with_any_case()
  • .search_one_line()
  • .search_global()

Functions

  • .replace( const std::string & source, const std::string & value )
  • .test()

Other

  • .add( expression )
  • .multiple( const std::string & value )
  • .alt()

Main metrics

Overview
Name With OwnerVerbalExpressions/CppVerbalExpressions
Primary LanguageC++
Program languageC++ (Language Count: 2)
Platform
License:MIT License
所有者活动
Created At2013-07-27 16:45:17
Pushed At2019-10-12 16:09:26
Last Commit At2017-04-16 23:03:02
Release Count0
用户参与
Stargazers Count385
Watchers Count37
Fork Count50
Commits Count48
Has Issues Enabled
Issues Count4
Issue Open Count2
Pull Requests Count7
Pull Requests Open Count1
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private