【问题标题】:Clojure Enlive: A selector that uses regexClojure Enlive:使用正则表达式的选择器
【发布时间】:2013-09-04 22:04:04
【问题描述】:

我正在尝试选择 :li 节点,其内容中包含单词“(SCIAN”:

<li>...</li>
<li class="">
                Conception de systèmes informatiques et services connexes (SCIAN 541510)
            </li>

<li>...</li>

我尝试这个失败了:

(html/select
    fetched
    [[:li (html/has [(html/re-pred #"\w*SCIAN\b")])]])))

感谢您的帮助!

注意:我尝试使用这些模式但没有成功,所以我可能会做错事: https://groups.google.com/forum/#!topic/enlive-clj/thlhc5zBRUw

【问题讨论】:

    标签: regex clojure enlive


    【解决方案1】:

    我认为正则表达式与法语口音相结合会导致问题:

        (def s "è")
        (def r #"\w") 
        (re-matches r s)
        ;;; => nil
        (def s "e")
        (re-matches r s)
        ;;; => "e"
    

    【讨论】:

    • 你是对的!我找到了解决办法,我们可以这样做:(re-matches #"\p{L}+" "è")
    • ...虽然我还不擅长正则表达式并且无法获得有效的解决方案。什么是正确的正则表达式选择器?
    【解决方案2】:

    要做到这一点,我们实际上不需要使用正则表达式:

    (html/select
        fetched
        [[:li (html/pred #(.contains (html/text %) "SCIAN"))]])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-07
      • 2010-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-22
      相关资源
      最近更新 更多