Git Product home page Git Product logo

cppverbalexpressions's Introduction

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

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

Special characters and groups

  • .any( const std::string & value )
  • .anyOf( const std::string & value )
  • .br()
  • .lineBreak()
  • .range( const std::initializer_liststd::string & args )
  • .tab()
  • .word()

Modifiers

  • .withAnyCase()
  • .searchOneLine()
  • .searchGlobal()

Functions

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

Other

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

cppverbalexpressions's People

Contributors

bilke avatar go-oleg avatar mihai-vlc avatar mpapierski avatar whackashoe avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.