• Stars
    star
    376
  • Rank 109,657 (Top 3 %)
  • Language
    C++
  • License
    MIT License
  • Created almost 11 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C++ regular expressions made easy

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

More Repositories

1

JSVerbalExpressions

JavaScript Regular expressions made easy
JavaScript
12,158
star
2

JavaVerbalExpressions

Java regular expressions made easy.
Java
2,608
star
3

PHPVerbalExpressions

PHP Regular expressions made easy
PHP
2,411
star
4

PythonVerbalExpressions

Python regular expressions made easy
Python
1,618
star
5

CSharpVerbalExpressions

C#
1,167
star
6

SwiftVerbalExpressions

Swift Port of VerbalExpressions
Swift
595
star
7

ObjectiveCVerbalExpressions

Objective-C
287
star
8

RVerbalExpressions

💬 Create regular expressions easily
R
279
star
9

GoVerbalExpressions

Go VerbalExpressions make regular expression easy
Go
178
star
10

KotlinVerbalExpressions

Kotlin regular expressions made easy.
Kotlin
157
star
11

ScalaVerbalExpressions

Scala
80
star
12

DartVerbalExpressions

Dart Regular expressions made easy.
Dart
71
star
13

ClojureVerbalExpressions

Clojure
70
star
14

HaskellVerbalExpressions

Haskell
63
star
15

QtVerbalExpressions

C++
60
star
16

ElixirVerbalExpressions

Elixir
46
star
17

RustVerbalExpressions

Rust Port of VerbalExpressions
Rust
44
star
18

HaxeVerbalExpressions

Verbal Expressions for Haxe
Haxe
42
star
19

FSharpVerbalExpressions

Compoable F# regular expressions made easy
F#
38
star
20

implementation

In this repo we will document how each method in the library should behave
34
star
21

elm-verbal-expressions

Elm Regular expressions made easy
Elm
33
star
22

purescript-verbal-expressions

Purescript Regular expressions made easy
PureScript
24
star
23

PowerShellVerbalExpressions

PowerShell
24
star
24

PerlVerbalExpressions

Perl Regular expressions made easy
Perl
17
star
25

LuaVerbalExpressions

Lua Regular expressions made easy
Lua
13
star
26

GroovyVerbalExpressions

Groovy regular expressions made easy
Groovy
13
star
27

verbalExpressions.github.io

HTML
9
star
28

ValaVerbalExpressions

Vala regular expressions made easy
Vala
8
star
29

AS3VerbalExpressions

ActionScript
8
star
30

ErlangVerbalExpressions

Erlang
7
star
31

FreeBasicVerbalExpressions

FreeBASIC port
FreeBasic
7
star
32

DVerbalExpressions

D
6
star
33

RacketVerbalExpressions

Racket
4
star
34

DenoVerbalExpressions

TypeScript
2
star
35

GenieVerbalExpressions

Genie regular expressions made easy
JavaScript
2
star