pavany
pavany

Reputation: 219

REGEX to find the class name for style property in html file

Hello friends I got a requirement to find the class for the styple property in html file.For that I have to use REGEX. Please check below details

property is font-style:italic

corresponding class that i should find out is .csF52F8E4D

please check below link for the requirement.

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

the Regular expression that i wrote is

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

can any one please help me how to identify the class name for the given property

Upvotes: 1

Views: 72

Answers (2)

revo
revo

Reputation: 48711

Use positive lookaheads:

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

Live demo

Upvotes: 2

user557597
user557597

Reputation:

I guess you could generalize it where the selector is in group 1.

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

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

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

Upvotes: 1

Related Questions