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.
[philjackson/two-probs "0.1.0"]
compile "philjackson:two-probs:0.1.0"
<dependency>
<groupId>philjackson</groupId>
<artifactId>two-probs</artifactId>
<version>0.1.0</version>
</dependency>
(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 "bob@example.com"))) => "example"
group
- Groupexpressions
, truthy final arity determines capturing status.cap
- Capturing group.non-cap
- Non-capturing group.zero-or-more
- Match zero or more instances ofexpressions
.zero-or-one
-one-or-more
- Match one or more instances ofexpressions
.re-or
- Returnsexpressions
logically or'd together.literal
- Returns a quoted version of expression that can be used as a literal in a regexp.times
- Matchexpression
a minimum ofmn
times and a maximum ofmx
times.
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
)
Copyright © 2015 Phil Jackson
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.