On Wednesday 03 December 2008 11:57, Blaine wrote: > I want to build a regular expression pattern literal (I think that's > what they're called) like #"a.*" out of separate strings like "a" and > ".*". > > user> (re-seq #"a.*" "bab") ; this is cool > ("ab") > user> (re-seq #(str "a" ".*") "bab") ; but this, in all its > noobness, is not > ; Evaluation aborted. > user> #(str "a" ".*") > #<user$eval__4569$fn__4571 [EMAIL PROTECTED]> ; what > is this thing? can I use it somehow?
You're using a reader notation unrelated to regular expressions. Instead, #(...) is a shorthand notation for an anonymous function definition. In this case, you'll have to build up the textual form of the pattern (being careful to use all the necessary extra backslashes) and then when that's complete, use (re-pattern ...) to turn that string into a Pattern instance. Perhaps more easily, you can combine the string concatenation with the Pattern compilation in a single form: (re-pattern (str "a" ".*" "b")) or (re-seq (re-pattern (str "a" ".*" "b")) "babba") user=> (re-seq (re-pattern (str "a" ".*" "b")) "babba") ("abb") > I appreciate the help. > > - Blaine Randall Schulz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---