On Mon, Mar 18, 2013 at 12:48 PM, Marko Topolnik
<[email protected]>wrote:
>
> On Monday, March 18, 2013 8:37:19 PM UTC+1, Stefan Kamphausen wrote:
>>
>>
>> this works pretty well, at least better than I expected, e.g.:
>>
>> user=> (def r1 #"(\s.)")
>> #'user/r1
>> user=> (def r2 #"([abc])")
>> #'user/r2
>> user=> (def r3 (re-pattern (str r1 "|" r2)))
>> #'user/r3
>> user=> r3
>> #"(\s.)|([abc])"
>> user=> (re-find r3 " x")
>> [" x" " x" nil]
>> user=> (re-find r3 "b")
>> ["b" nil "b"]
>>
>
> This is a nice trick, but obviously isn't universal: it works only if you
> build up from parts that are literal regexes. More often that not this will
> not be the case.
>
str is based on the toString() method of java.util.regex.Pattern, so I do
not understand why you say it only works if you build up from parts that
are literal regexes. For example:
user=> (def r1 (re-pattern "\\sfoo|bar\\d+"))
#'user/r1
user=> (def r2 (re-pattern "taking over the world( world)*\\b"))
#'user/r2
user=> (def r3 (re-pattern (str "(" r1 ")|(" r2 ")")))
#'user/r3
user=> r3
#"(\sfoo|bar\d+)|(taking over the world( world)*\b)"
user=> (re-find r3 "I don't like this fooing weather")
[" foo" " foo" nil nil]
user=> (re-find r3 "We should be taking over the world soon")
["taking over the world" nil "taking over the world" nil]
Andy
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.