Frak takes an entirely different approach to generating regular expressions
Hot on the heals of our Verbal Expressions coverage comes Frak by Joel Holdbrooks.
Frak also generates regular expressions for you, but it does it in a completely different way. With Frak, you don’t write an expression to match string patterns. Instead, you give it a set of strings and it generates an expression which matches them.
Frak is written in Clojure, so you install it by adding a dependency to your project.clj
file:
[frak "0.1.2"]
To use it, simply require it, pass it a collection of strings, and it will return the resulting regular expression:
user> (require 'frak)
nil
user> (frak/pattern ["foo" "bar" "baz" "quux"])
#"(?:ba[rz]|foo|quux)"
user> (frak/pattern ["Clojure" "Clojars" "ClojureScript"])
#"Cloj(?:ure(?:Script)?|ars)"
Check out the README to learn how it works, see some benchmarks, and get frak’in!
Discussion
Sign in or Join to comment or subscribe