C++ regular expressions made easy

Overview

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

    Thanks.

    opened by mpapierski 1
  • 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
  • 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.

    image

    Thanks.

    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
Owner
null
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 585 Dec 6, 2022
SRL-CPP is a Simple Regex Language builder library written in C++11 that provides an easy to use interface for constructing both simple and complex regex expressions.

SRL-CPP SRL-CPP is a Simple Regex Language builder library written in C++11 that provides an easy to use interface for constructing both simple and co

Telepati 0 Mar 9, 2022
A Compile time PCRE (almost) compatible regular expression matcher.

Compile time regular expressions v3 Fast compile-time regular expressions with support for matching/searching/capturing during compile-time or runtime

Hana Dusíková 2.6k Jan 5, 2023
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 4k Jan 1, 2023
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.9k Jan 3, 2023
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 7.5k Jan 4, 2023
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 72 Dec 6, 2022
A system to flag anomalous source code expressions by learning typical expressions from training data

A friendly request: Thanks for visiting control-flag GitHub repository! If you find control-flag useful, we would appreciate a note from you (to niran

Intel Labs 1.2k Dec 30, 2022
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 320 Oct 9, 2022
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 585 Dec 6, 2022
A powerful and fast search tool using regular expressions

A powerful and fast search tool using regular expressions

Stefan Küng 1.3k Jan 8, 2023
SRL-CPP is a Simple Regex Language builder library written in C++11 that provides an easy to use interface for constructing both simple and complex regex expressions.

SRL-CPP SRL-CPP is a Simple Regex Language builder library written in C++11 that provides an easy to use interface for constructing both simple and co

Telepati 0 Mar 9, 2022
tiny recursive descent expression parser, compiler, and evaluation engine for math expressions

TinyExpr TinyExpr is a very small recursive descent parser and evaluation engine for math expressions. It's handy when you want to add the ability to

Lewis Van Winkle 1.2k Jan 6, 2023
tiny recursive descent expression parser, compiler, and evaluation engine for math expressions

TinyExpr TinyExpr is a very small recursive descent parser and evaluation engine for math expressions. It's handy when you want to add the ability to

Lewis Van Winkle 1.2k Dec 30, 2022
A simple implementation of a parser and its use to calculate simple mathematical expressions

Calculator C Parser A simple implementation of a parser and its use to calculate simple mathematical expressions I haven't written a detailed descript

Romes 14 Nov 8, 2021
A single-header C/C++ library for parsing and evaluation of arithmetic expressions

ceval A C/C++ header for parsing and evaluation of arithmetic expressions. [README file is almost identical to that of the ceval library] Functions ac

e_t 9 Oct 10, 2022
A single-header C/C++ library for parsing and evaluation of arithmetic expressions

ceval A C/C++ header for parsing and evaluation of arithmetic expressions. [README file is almost identical to that of the ceval library] Functions ac

e_t 9 Oct 10, 2022
compile time symbolic differentiation via C++ template expressions

SEMT - Compile-time symbolic differentiation via C++ templates The SEMT library provides an easy way to define arbitrary functions and obtain their de

null 14 Apr 8, 2022
A C/C++ library for parsing and evaluation of arithmetic expressions.

ceval A C/C++ header for parsing and evaluation of arithmetic expressions. Functions accessibe from main() Function Argument(s) Return Value ceval_res

e_t 6 Nov 8, 2022