V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
llhh

问个正则表达式的问题

  •  
  •   llhh · Nov 24, 2014 · 2229 views
    This topic created in 4180 days ago, the information mentioned may be changed or developed.
    想把下面的正则表达式浓缩下只有一个(.+?)。
    class="g">(.+?)</span>|<span class="c-showurl">(.+?)</span>

    匹配class="g">开头儿或者<span class="c-showurl">(.+?)开头,</span>结尾的字符串

    多谢。
    3 replies    2014-11-24 16:57:40 +08:00
    imn1
        1
    imn1  
       Nov 24, 2014   ❤️ 1
    class="(?:g|c-showurl)">(.+?)</span>
    imn1
        2
    imn1  
       Nov 24, 2014   ❤️ 1
    class="(?:g|c-showurl)"[^>]*?>(.+?)</span>
    这样保险一点,因为不能确定class是最后一个属性
    xylophone21
        3
    xylophone21  
       Nov 24, 2014
    你想怎么处理
    <span class = "c-showurl">...<sth class="c-showurl">...</sth></span>
    ?

    纯正则角度
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2639 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 11:53 · PVG 19:53 · LAX 04:53 · JFK 07:53
    ♥ Do have faith in what you're doing.