C++ regular expressions made easy

Related tags



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.


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()
            .then( "http" )
            .maybe( "s" )
            .then( "://" )
            .maybe( "www." )
            .anything_but( " " )

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



  • .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()


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


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


  • .add( expression )
  • .multiple( const std::string & value )
  • .alt()
  • how can we get

    how can we get

    we can test and replace but how can we get the match part from the source string

    opened by dry11orange 6
  • What does this error mean?

    What does this error mean?

    i have finished installing boost library, running cmake and make, but when i run CppVerbalExpressionsExample, i got following error:

    terminate called after throwing an instance of 'std::regex_error' what(): regex_error Aborted

    opened by lqniunjunlper 3
  • CMake makefile

    CMake makefile

    This pull request adds a CMake makefile for building the example with CMake.

    I have tested this on Mac OS with gcc 4.7.

    opened by bilke 1
  • It's just wrong to call it Singleton.

    It's just wrong to call it Singleton.

    I somewhat raged at the whole 'verbal expressions' thing and all that hype about it. I do not understand why you all make regexp even worse.

    Anyway let's be right about few things in this port.

    First of all C++11 support for regexps is good. Only few standard libraries do not implement this. But I can argue with this as for now. Also, you are calling "VerbEx()" a singleton which is not true. This is just object instantiation and all that verbal expression magic is just a method chaining through returning reference to this.

    Please consider merging my fixes as I think many novice programmers could see this C++ port (through reading Verbal Expressions written in JavaScript through hackernews or something like that) and learn wrong about important aspects of this language.


    opened by mpapierski 1
  • initial commit

    initial commit

    C++ port of verbal expressions

    opened by whackashoe 0
  • Updated range function, updated readme api

    Updated range function, updated readme api

    Old function was limited to numbers, used a vector for some sleepy reason. New one has error checking, uses an initializer list.

    opened by whackashoe 0
  • Refactor


    opened by whackashoe 0
  • Fix broken headings in Markdown files

    Fix broken headings in Markdown files

    GitHub changed the way Markdown headings are parsed, so this change fixes it.

    See bryant1410/readmesfix for more information.

    Tackles bryant1410/readmesfix#1

    opened by bryant1410 0
  • release


    Can you please make a release with a version? So source code will be available through release link.

    opened by ozenozkaya 0
  • Fixed C4458 warning on line 162 due to source having same name

    Fixed C4458 warning on line 162 due to source having same name

    Hi, Thanks for this class, it's been very useful.

    This PR fixes a C4458 warning on line 162 because it receives a "source" and has a class member var with same name. Personally I usually go with _ but in this case renaming it to src was the least distruptive change, I hope that's ok.

    Also made a few functions const and replaced a couple string::find with the char equivalent.



    opened by DJLink 0
  • Conan package

    Conan package

    Hello, Do you know about Conan? Conan is modern dependency manager for C++. And will be great if your library will be available via package manager for other developers.

    Here you can find example, how you can create package for the library.

    If you have any questions, just ask :-)

    opened by ZaMaZaN4iK 1
Onigmo is a regular expressions library forked from Oniguruma.

Onigmo (Oniguruma-mod) https://github.com/k-takata/Onigmo Onigmo is a regular expressions library forked from Oniguruma. It focuses to support new exp

K.Takata 548 Oct 14, 2021
regular expression library

Oniguruma https://github.com/kkos/oniguruma Oniguruma is a modern and flexible regular expressions library. It encompasses features from different reg

K.Kosako 1.6k Oct 19, 2021
A small implementation of regular expression matching engine in C

cregex cregex is a compact implementation of regular expression (regex) matching engine in C. Its design was inspired by Rob Pike's regex-code for the

Jim Huang 64 Jul 6, 2021
Perl Incompatible Regular Expressions library

This is PIRE, Perl Incompatible Regular Expressions library. This library is aimed at checking a huge amount of text against relatively many regular

Yandex 301 Sep 21, 2021
High-performance regular expression matching library

Hyperscan Hyperscan is a high-performance multiple regex matching library. It follows the regular expression syntax of the commonly-used libpcre libra

Intel Corporation 3.3k Oct 12, 2021
The approximate regex matching library and agrep command line tool.

Introduction TRE is a lightweight, robust, and efficient POSIX compliant regexp matching library with some exciting features such as approximate (fuzz

Ville Laurikari 642 Oct 21, 2021
Super Light Regexp engine for C/C++

SLRE: Super Light Regular Expression library Documentation and API reference are at docs.cesanta.com/slre Contributions To submit contributions, sign

Cesanta Software 487 Sep 13, 2021
A non-backtracking NFA/DFA-based Perl-compatible regex engine matching on large data streams

Name libsregex - A non-backtracking NFA/DFA-based Perl-compatible regex engine library for matching on large data streams Table of Contents Name Statu

OpenResty 571 Oct 5, 2021
RE2 is a fast, safe, thread-friendly alternative to backtracking regular expression engines like those used in PCRE, Perl, and Python. It is a C++ library.

This is the source code repository for RE2, a regular expression library. For documentation about how to install and use RE2, visit https://github.co

Google 6.1k Oct 16, 2021