Fork me on GitHub
#clojure-spec
<
2018-05-22
>
troglotit13:05:51

Hey! I want to spec for five characters long numbers: I could use regexes #(re-matches #"\d{5}" %), but I as far as I can understand that could be done in spec. I looked up a bit, but what I found is only s/* s/+ s/? that kind of operators. So, is there that kind of spec? I know about s/cat - but that seem too overkill for when I just want to repeat my regex

ghadi13:05:45

while they may work for characters of sequences, I wouldn't use s/* s/+ etc. for that

ghadi13:05:15

if you're parsing strings, a normal regex is more appropriate

troglotit13:05:40

Oh, I found (s/every :count) - seems like what I wanted

ghadi13:05:38

like i said, it's a bad idea

ghadi13:05:19

the regex predicate you have up there is the better approach

troglotit13:05:31

I want to have more composable regexes and spec seem suited for that, compared to regular regexes

Alex Miller (Clojure team)13:05:33

spec is not designed to be a good string regex parser and is unlikely to perform or work well for that use case as actual regex or a parser

Alex Miller (Clojure team)13:05:04

I want to say there is something else like this out there for composable regexes too

bbrinck14:05:42

@troglotit The comment thread on this reddit post goes into some of the issues you may run into when using spec for parsing strings https://www.reddit.com/r/Clojure/comments/7vwpu4/parsing_with_clojurespec/