title: Clojure re-find reg-ex OR
body: <p>I've been trying to get a simple reg-ex working in Clojure to test a string for some SQL reserved words (select, from, where etc.) but just can't get it to work:</p>
  
  <pre><code>(defn areserved? [c]
    (re-find #"select|from|where|order by|group by" c))
  </code></pre>
  
  <p>(I split a string by spaces then go over all the words)</p>
  
  <p>Help would be greatly appreciated,</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p><strong>EDIT</strong>: My first goal (after only reading some examples and basic Clojure materials) is to parse a string and return for each part of it (i.e. words) what "job" they have in the statement (a reserved word, a string etc.).</p>
  
  <p>What I have so far:</p>
  
  <pre><code>(use '[clojure.string :only (join split)])
  
  (defn isdigit? [c]
    (re-find #"[0-9]" c))
  
  (defn isletter? [c]
    (re-find #"[a-zA-Z]" c))
  
  (defn issymbol? [c]
    (re-find #"[\(\)\[\]!\.+-&gt;&lt;=\?*]" c))
  
  (defn isstring? [c]
    (re-find #"[\"']" c))
  
  (defn areserved? [c]
    (if (re-find #"select|from|where|order by|group by" c)
        true
        false))
  
  (defn what-is [token]
    (let [c (subs token 0 1)]
      (cond
        (isletter? c)  :word
        (areserved? c) :reserved
        (isdigit? c)   :number
        (issymbol? c) :symbol
        (isstring? c) :string)))
  
  (defn checkr [token]
    {:token token
     :type (what-is token)})
  
  (defn goparse [sql-str]
    (map checkr (.split sql-str " ")))
  </code></pre>
  
  <p>Thanks for all the help guys! it's great to see so much support for such a relatively new language (at least for me :) )</p>