tumbin tumbin - 6 months ago 16
PHP Question

regex for css class and id

I want to insert all class and id of css file in database rows,

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;}


from subscribe p i only want subscribe not p so basically i am looking for some regex which will filter elements between
.
and
{
or space from each class:

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


I have to search between
.
and
{
and for

.subscribe p{


I have to search between
.
and space

Answer

This regex should be able to find classes and ids in your stylesheet.

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

Demo: https://regex101.com/r/xB0dZ6/1

It pretty much says the string must start with a # or . then contain at least one alphanumerical character, ., -, or _.

Comments