I have this multiple lines CSS style:
.style-1 {
border-color: #2980B9;
}
.style-2 {
background-color: #2980B9;
#FFF;
}
.style-3 input[type=submit] {
background-color: #2980B9;
color: #FFF;
}
And here is my regex pattern: \\..*\\{\\s?\\s?+.*\\s?\\}\\s?\\s?+
https://regex101.com/r/tP7qE7/1
I want to match each rule from the selector until the closing bracket so I can prepend new selector to each rule and echo each rule separately. Right now with my regex pattern above I can get only the first rule. I tried both preg_match()
and preg_match_all()
but with no success. How can I match each rule using regex?
Thank you in advance!
You can use the following regex ( \\..*?\\{.*?\\}
) with g
and s
modifiers:
/\..*?\{.*?\}/gs
See DEMO
您可以尝试此模式以匹配选择器
(?s)^\..*?\{.*?\}$
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.