Clojure regexs

2011-01-13 Thread Alex Baranosky
So I am converting some Ruby code I have into CLojure for practice/fun and I am having trouble finding info via Google. I want to take something like this from Ruby and do it in Clojure: DATE_REGEX = /^\s*(\d{4})\s+(\d{1,2})\s+(\d{1,2})/ token =~ DATE_REGEX [$1, $2, $3] So far my best guess

Re: Clojure regexs

2011-01-13 Thread Eric Lavigne
So I am converting some Ruby code I have into CLojure for practice/fun and I am having trouble finding info via Google. Clojure uses the same regex style as Java, so you'll need to search for information on Java regexes rather than Clojure regexes. -- You received this message because you are

Re: Clojure regexs

2011-01-13 Thread .Bill Smith
Here is one way: user= (import 'java.util.regex.Pattern) java.util.regex.Pattern user= (def p (Pattern/compile mon|tue|wed|thu|fri|sat|sun Pattern/CASE_INSENSITIVE)) #'user/p user= (re-find p I have a dentist appoint on Monday morning, so you'll need to take the kids to school.) Mon Bill On

Re: Clojure regexs

2011-01-13 Thread gaz jones
i think you want to do something like this: (let [_ year month day] (re-find date-regex line)) On Thu, Jan 13, 2011 at 8:50 PM, Eric Lavigne lavigne.e...@gmail.com wrote: So I am converting some Ruby code I have into CLojure for practice/fun and I am having trouble finding info via Google.

Re: Clojure regexs

2011-01-13 Thread Alex Baranosky
I see. So I may have to use some kind of clunky syntax instead of a nice $1, $2, $3 syntax. I can handle that I guess :) Thanks. -- 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 Note that

Re: Clojure regexs

2011-01-13 Thread Alex Baranosky
A blog entry I read (and now can't find) mentioned being able to use syntax like (?i) to do the ignore case. -- 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 Note that posts from new members

Re: Clojure regexs

2011-01-13 Thread Benny Tsai
For accessing groups in a match, you can use (re-matches). It will always give the full match as the first element though: user= (re-matches date-regex 2011 1 13) [2011 1 13 2011 1 13] So to replicate the Ruby code's behavior maybe you'll just want (rest (re-matches date-regex line)). For

Re: Clojure regexs

2011-01-13 Thread Ken Wesson
On Thu, Jan 13, 2011 at 9:54 PM, Alex Baranosky alexander.barano...@gmail.com wrote: I see.  So I may have to use some kind of clunky syntax instead of a nice $1, $2, $3 syntax.  I can handle that I guess :) Hey, it's a Lisp! You can use almost any syntax you want. How about %1, %2, %3: (defn

Re: Clojure regexs

2011-01-13 Thread gaz jones
bah! good catch. (let [[_ year month day]] (re-find date-regex line)) fixed! On Thu, Jan 13, 2011 at 9:03 PM, Ken Wesson kwess...@gmail.com wrote: On Thu, Jan 13, 2011 at 9:54 PM, Alex Baranosky alexander.barano...@gmail.com wrote: I see.  So I may have to use some kind of clunky syntax

Re: Clojure regexs

2011-01-13 Thread Ken Wesson
On Thu, Jan 13, 2011 at 10:22 PM, gaz jones gareth.e.jo...@gmail.com wrote: bah! good catch. (let [[_ year month day]] (re-find date-regex line)) fixed! Oh, gaz. I'm so so sorry. :( -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this

Re: Clojure regexs

2011-01-13 Thread gaz jones
lol oh noes! i should really stop doing this while watching 30rock... On Thu, Jan 13, 2011 at 9:38 PM, Ken Wesson kwess...@gmail.com wrote: On Thu, Jan 13, 2011 at 10:22 PM, gaz jones gareth.e.jo...@gmail.com wrote: bah! good catch. (let [[_ year month day]] (re-find date-regex line)) fixed!