Giter Site home page Giter Site logo

two-probs's Introduction

Now you've got Two Problems

If you're unlucky enough to have to process large regexps, this library should help you make them more readable, composable and maintainable.

It's very simple - don't expect magic.

Install

Leiningen

[philjackson/two-probs "0.1.0"]

Gradle

compile "philjackson:two-probs:0.1.0"

Maven

<dependency>
  <groupId>philjackson</groupId>
  <artifactId>two-probs</artifactId>
  <version>0.1.0</version>
</dependency>

Usage

(ns two-probs-examples
  (:require [two-probs.core :refer :all]))

;; simple email matching pattern
(let [email (re-pattern
             (re [:beg
                  (one-or-more :word true)
                  \@
                  (cap (one-or-more [:word]))
                  \.
                  (one-or-more :word)
                  :end]))]
  (second (re-matches email "[email protected]"))) => "example"

Functions

  • group - Group expressions, truthy final arity determines capturing status.
  • cap - Capturing group.
  • non-cap - Non-capturing group.
  • zero-or-more - Match zero or more instances of expressions.
  • zero-or-one -
  • one-or-more - Match one or more instances of expressions.
  • re-or - Returns expressions logically or'd together.
  • literal - Returns a quoted version of expression that can be used as a literal in a regexp.
  • times - Match expression a minimum of mn times and a maximum of mx times.

Simple chars

What's produced by Two Problems and the aliases you can use:

  • \W (:W, :non-word)
  • \A (:A, :beginning-input, :beg-input, :beg-in)
  • \b (:b, :boundary, :bndry)
  • \B (:B, :non-boundary, :non-bndry)
  • \w (:w, :word)
  • \Z (:Z, :end-term)
  • \S (:S, :non-space)
  • \z (:z, :end-input, :end-in)
  • \D (:D, :non-digit)
  • . (:., :any)
  • \d (:d, :digit)
  • \s (:s, :space)
  • ^ (:start, :beg, :beginning)
  • $ (:$, :end)
  • \G (:G, :end-match)

License

Copyright © 2015 Phil Jackson

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

two-probs's People

Contributors

philjackson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 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.