【问题标题】:regex for css class and idcss 类和 id 的正则表达式
【发布时间】:2016-09-26 17:37:45
【问题描述】:

我想在数据库行中插入css文件的所有类和id,

html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,dl,dt,dd,ol,nav ul,nav li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline;}
article, aside, details, figcaption, figure,footer, header, hgroup, menu, nav, section {display: block;}
ol,ul{list-style:none;margin:0;padding:0;}
.subscribe p{
.txt-rt{text-align:right;}
.pos-relative{position:relative;}

从订阅 p 我只想订阅而不是 p 所以基本上我正在寻找一些正则表达式,它将过滤 .{ 之间的元素或每个类的空间:

.txt-rt{text-align:right;}

我必须在 .{ 之间进行搜索,并寻找

.subscribe p{

我必须在. 和空格之间进行搜索

【问题讨论】:

  • 可能类似于[.#]([\w.-]+)regex101.com/r/xB0dZ6/1 在第一组规则中,您希望什么都找不到?
  • 我希望将这些项目输入到mysql的一行中
  • 请给出我会接受的答案。它解决了我的问题

标签: php html css regex


【解决方案1】:

这个正则表达式应该能够在您的样式表中找到类和 ID。

[.#]([\w.-]+)

演示:https://regex101.com/r/xB0dZ6/1

它几乎说字符串必须以#. 开头,然后至少包含一个字母数字字符.-_

您可能想要添加一个起始锚点或尾随检查,.*?{。和

一样
marque {
     width: 2.2px
}

.2px 将匹配此规则。

【讨论】:

    猜你喜欢
    • 2014-05-26
    • 2015-09-30
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-24
    相关资源
    最近更新 更多