Can this be done without a complicated regex

Hello,

Im busy with a challenge of exercism
I have a line like this :

[error] :  This is a error message 

So now I have to take out the error part which can also be info or warning and the actual text.
Is there a way I can make this work without a complicated regex ?
If not, can anyone help me to figure out how the regex must look like ?

1 Like

First thought:

user> (def s "[error] :  This is a error message ")
#'user/s
user> (->> (clojure.string/split s #":")
           (map clojure.string/trim))
("[error]" "This is a error message")

And here’s a regex in case that’s helpful:

user> (re-find #"\[([^\]]+)\]\s+:\s+(.+)$" s)
["[error] :  This is a error message " "error" "This is a error message "]
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.