正则表达式 - 在组后追加,将内容保留在中间
Regex - Append after group, keep content in-between
我需要一些帮助来解决特殊情况,在我自己的编译器中。
思路是转
@media screen and (min-width:1280px) {
@media screen and (min-width:1088px) and (max-width:1279px) {
进入
@media screen and (min-width:1280px) { #test-id
@media screen and (min-width:1088px) and (max-width:1279px) { #test-id
(在开头括号后附加#test-id)
我看到地上的两根木桩是“@media”和“{”。
考虑到这一点,有哪些可能的正则表达式解决方案来保留“@media”(...)“{”中的代码并附加“#test-id”?
用于匹配和替换的原始正则表达式会有所帮助。
干杯!
您可以使用表达式:
(^@media[^{]+{)
(
捕获组。
^
断言行首位置。
@media
匹配文字子串。
[^{]+
匹配除 {
. 以外的任何内容
{
匹配一个{
.
)
关闭捕获组。
替换为:
#test-id
您可以实时试用正则表达式 here。
我需要一些帮助来解决特殊情况,在我自己的编译器中。
思路是转
@media screen and (min-width:1280px) {
@media screen and (min-width:1088px) and (max-width:1279px) {
进入
@media screen and (min-width:1280px) { #test-id
@media screen and (min-width:1088px) and (max-width:1279px) { #test-id
(在开头括号后附加#test-id)
我看到地上的两根木桩是“@media”和“{”。 考虑到这一点,有哪些可能的正则表达式解决方案来保留“@media”(...)“{”中的代码并附加“#test-id”?
用于匹配和替换的原始正则表达式会有所帮助。
干杯!
您可以使用表达式:
(^@media[^{]+{)
(
捕获组。^
断言行首位置。@media
匹配文字子串。[^{]+
匹配除{
. 以外的任何内容
{
匹配一个{
.)
关闭捕获组。
替换为:
#test-id
您可以实时试用正则表达式 here。