I need a regex to change this:
.my-class {
@apply .p-4 .bg-red-500;
}
into this:
.my-class {
@apply p-4 bg-red-500;
}
I found this regex but it is not working:
(?<=@apply.*).
any ideas?
I need a regex to change this:
.my-class {
@apply .p-4 .bg-red-500;
}
into this:
.my-class {
@apply p-4 bg-red-500;
}
I found this regex but it is not working:
(?<=@apply.*).
any ideas?
2
Answers
Managed to change all sass files in a directory like this:
Your regex will work in .NET or Python PyPi
regex
module or JavaScript ECMAScript 2018+ compliant environments that support infinite-width lookbehind patterns.If it is PCRE/Java/Ruby, you can use
And replace with
$1
backreference to Group 1. See the regex demo. I assumed you want to find dots on the same line as@apply
, so I addedr
andn
to the negated character class, if it is not so, remover
andn
.Details:
((?:G(?!^)|@apply)[^.rn]*)
– Group 1: either the end of the previous successful match (G(?!^)
) or@apply
and then zero or more chars other than a dot, CR and LF chars.
– a dot