Question

I want to write a regex, which would help to match sequence of symbol } and append string before it. Here's the example text that I want to substitute:

@media (max-width: 600px){#oaw {color: #ccc} #oaw .oa-form form button{width:100%}}

Should become:

@media (max-width: 600px){#oaw {color: #ccc !important} .oa-form form button{width:100% !important}}

I want to match every occurrence of }+ and replace it with !important}+ so that the following replacements would be done:

} -> !important}
}} -> !important}}
and so on..

Is there any way that I could tell regex to match }+ and append !important before it (replace it with custom string and append matched string)?

Was it helpful?

Solution

Just try with matching:

(} *}?)

and replacing with

 !important $1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top