Skip to content

String split with regex

String splitting using a regex patternλ︎

clojure.string/split takes a string to be split and a pattern to split the string with.

(clojure.string/split "This is a string    that I am splitting." #"\s+")
   ["This" "is" "a" "string" "that" "I" "am" "splitting."]

Most common words exampleλ︎

Extract a list of the most commonly used English words, returned as a string of words that are separated by a comma.

The #"," regex pattern splits the string of words to form a collection of individual words, each word being its own string.

(def common-english-words
  (set
    (clojure.string/split
      (slurp
        "http://www.textfixer.com/resources/common-english-words.txt")
      #",")))

TODO: add link to complete example.