Advertisement
Guest User

Untitled

a guest
Dec 16th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn extract-links
  2.   [matcher]
  3.   (loop [rs []]
  4.     (if-let [next (re-find matcher)]
  5.       (recur (conj rs next))
  6.       rs)))
  7.  
  8. (defn decompose-link
  9.   [link]
  10.   (let [[_ url]
  11.         (re-find (re-matcher #"href=[\'\"](.*)[\'\"]"
  12.                              (.replaceAll link " " "")))]
  13.     [url (.replaceAll (re-matcher #"<.+?>" link) "")]))
  14.  
  15. (defn array-links
  16.   [desc]
  17.   (let [matcher (re-matcher #"<a.+?</a>" desc)
  18.         links (extract-links matcher)]
  19.     (interleave (string/split
  20.                           (.replaceAll matcher "!!")
  21.                           #"!!") (map decompose-link links))))
  22.  
  23. (array-links (str "A classic, <a href=\"foo\">1111111</a> wear-with-everything "
  24.                   "sweater with nautical-inspired anchor buttons at the "
  25.                   "neck. \n(We're also keeping it at the very top of our "
  26.                   "vacation <a href =\"bar\">22222</a> packing list, "
  27.                   "for plane rides or breezy beach nights.)"))
  28.  
  29. (decompose-link (str "A classic, <a href=\"foo\">1111111</a> wear-with-everything "
  30.                      "sweater with nautical-inspired anchor buttons at the "
  31.                      "neck. \n(We're also keeping it at the very top of our "
  32.                      "vacation <a href=\"bar\">22222</a> packing list, "
  33.                      "for plane rides or breezy beach nights.)"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement