GithubHelp home page GithubHelp logo

rrrex's Introduction

Really Readable Regular Expressions

rrrex is a new syntax for regular expressions. It trades compactness for readability by real humans, and picks up a couple nice perks along the way.

Build Status

Crash Course

"The string you'd like to search".rmatch? { "string" }

"abc".rmatch? { "ab" + "c" }

"abc".rmatch? { "xyz".or "abc" }

You don't have to worry about escaping special characters in your strings any more:

"{symbols} .*&+ [galore]".rmatch? { "{symbols} .*&+ [galore]" }

You can combine operations and get the expected precedence:

"abc".rmatch? { "ab" + ( "z".or "c" ) }

You can use Rrrex.build to make reusable, composable objects:

names = Rrrex.build { "foo".or "bar" }
nums = Rrrex.build { "1".or "2" }
names.match "foo"
"foo112".rmatch? { names + ( some nums )}

Repetition:

"aaabc".rmatch? { 1.or_more "a" }
"aaabc".rmatch? { 5.or_less "a" }
"aaabc".rmatch? { 3.exactly "a" }
"aaabc".rmatch? { (1..5).of "a" }

These are equivalent:

"aaabc".rmatch? { 0.or_more "a" }
"aaabc".rmatch? { any "a" }

And these are equivalent:

"aaabc".rmatch? { 1.or_more "a" }
"aaabc".rmatch? { some "a" }

Repetition can be nongreedy:

"aaabc".rmatch? { 2.or_more "a", :greedy => false } # matches "aa"

Special character sets:

"abc1234.&*".rmatch? { 10.exactly any_char }
"abc1234".rmatch? { 3.exactly letter }
"abc1234".rmatch? { 4.exactly digit }
"abc_123".rmatch? { 7.exactly word_char }
" ".rmatch? { whitespace }

Or create your own:

"abc".rmatch? { 3.exactly "a".."c" }

Two types of negation:

"x".rmatch? { word_char.not "x" } # => nil
"y".rmatch? { word_char.not "x" }
"x".rmatch? { _not "x" } # => nil
"y".rmatch? { _not "x" }

Groups:

"aaabc".rmatch? { group(1.or_more "a") }[1]
"aaabc".rmatch? { group(:alpha, (1.or_more "a")) }[:alpha]

match = "1234567890       Central Processing".rmatch? do
    group :serial do
        some digit
    end + some whitespace + group :source do
        any any_char
    end
end
match

See the examples for more ideas.

rrrex's People

Contributors

iangreenleaf avatar graemeworthy avatar

Stargazers

Emilio Contreras avatar Angus H. avatar Jairo Diaz avatar Ivan Kotelnikov avatar Paul Hieromnimon avatar brownman avatar Guilherme da Silva Mello avatar Roberto Barros avatar Miroslav Malkin avatar Wael Nasreddine avatar Mani Tadayon avatar David A McClain avatar Fabio Mont Alegre avatar Sergey Nebolsin avatar Rafael Floresta avatar Jan-Erik Rediger avatar Carlos Brando avatar Zach Inglis avatar Ravil Bayramgalin avatar

Watchers

 avatar James Cloos avatar

rrrex's Issues

Allow standalone construction of objects

From John Stone:

Besides readability, the other advantage that TRegexp might provide is the possibility of building up regular expressions a little at a time, possibly assembling them from reusable components. Can the methods like some() take TRegexps as arguments, or only character sets?

Prettier emitted strings

Currently I'm building the Regexp strings with tons of unnecessary non-capturing groups. This is fine for computation, but ugly when humans want to examine the resulting Regexp.

Solving this is a little tricky, since I think I'll need to know something about the precedence of the objects.

Or I can cheat and use https://github.com/josh/regin.

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.