【问题标题】:REGEX to find the class name for style property in html file正则表达式在 html 文件中查找样式属性的类名
【发布时间】:2017-06-29 19:37:25
【问题描述】:

你好朋友,我需要在 html 文件中找到样式属性的类。为此,我必须使用正则表达式。请查看以下详细信息

属性是 font-style:italic

我应该找出的对应类是 .csF52F8E4D

请查看下面的链接以了解要求。

https://regex101.com/r/rIkAaN/1

我写的正则表达式是

(\.(..........){.*;.*;.*;.*;.*;font-style:italic;})

谁能帮我识别给定属性的类名

【问题讨论】:

    标签: html regex


    【解决方案1】:

    使用积极的前瞻:

    \.[\w-]+(?=[^{}]*{[^{}]*font-style\s*:\s*italic)
    

    Live demo

    【讨论】:

      【解决方案2】:

      我想你可以概括一下选择器在第 1 组中的位置。

      (\.[^{}]+?)\s*{[^{}]*?font-style\s*:\s*italic;[^{}]*?}

      https://regex101.com/r/rIkAaN/5

       (                             # (1 start)
            \.
            [^{}]+? 
       )                             # (1 end)
       \s* 
       {
       [^{}]*? 
       font-style
       \s* : \s* 
       italic
       ;
       [^{}]*? 
       }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-11-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多