Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple regex patterns in Clojure?

Tags:

regex

clojure

I'm trying to make my code more readable but still try have as much sense as possible, I would like to test a string vs a few regex patterns.

( re-find #"(?i)(^select .* from .*)|(^delete from me)" c))

And I would like to split this into 2 separate patterns but maybe use one test? is there anything that would test a set of patterns vs 1 string?

Thanks!

like image 446
R X Avatar asked May 05 '26 15:05

R X


1 Answers

(def patterns [#"(?i)^select .* from .*" #"(?i)^delete from me"])

(when (some #(re-find % "your test string") patterns)
 ...)

clojure.core/some

like image 175
Kyle Avatar answered May 08 '26 12:05

Kyle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!