I would like to match string like this with regEx:
@media only screen and (max-width: 479px){
.abv{style:value;style:value}
.xyz{style:value;style:value}
}
but somehow I cant.
My regEx start with / @media[^{]*\{ /gim
then a want to match everything except }} folow by }}
/@media[^{]*\{[^}}]*\}(?=})/gim -this is not working because [^}}] == [^}] … I have no idea how to make regEx working like this please help
You want this:
See it here on Regexr
You don’t need the
mmodifier, it works only on the anchors^and$You meant the
smodifier to make the.match also newline characters. You didn’t use the.in your regex, but I did.What you want to achieve is possible with this construct
(?:(?!\}\s*\}).)*it means match the next character only if it is not a}followed by another}with possibly whitespace in between. This assertion is ensured by the negative lookahead(?!\}\s*\}). The group starting with?:is only a non capturing group, nothing special.