0

我正在尝试获取可以执行这些情况的正则表达式:

情况1:

background: -webkit-linear-gradient(top, #RANDOM_COLOR, #RANDOM_COLOR);

background: -ms-linear-gradient(top, #RANDOM_COLOR, #RANDOM_COLOR); 
background: -webkit-linear-gradient(top, #RANDOM_COLOR, #RANDOM_COLOR);

案例2

box-shadow: RANDOM_TEXT;

-webkit-box-shadow: RANDOM_TEXT;
box-shadow: RANDOM_TEXT;

然后我只想使用 Dreamweaver 中的 Control+F 功能并使用正则表达式替换文本。

Dreamweaver 替换功能

谢谢

4

3 回答 3

1

Dreamweaver 使用的是 Javascript Regex 风格。

找到 1:

([ \t]*)(background:\s*-webkit-linear-gradient\(top\s*,\s*(#[a-fA-F0-9]{3,6})\s*,\s*(#[a-fA-F0-9]{3,6})\s*\)\s*;)
// assuming these are hexadecimal colors like you indicated with #

替换1:

$1background: -ms-linear-gradient(top, $3, $4); 
$1$2

找到 2:

([ \t]*)(box-shadow:\s*([^;]+)\s*;)

替换2:

$1-webkit-box-shadow: $3;
$1$2


第一个查找模式的解释:

所有空格字符\s都是可选的(感谢*)。此外,文字括号被转义。在替换中$1$2等表示[capturingGroup n]

(                          # capturing group #1
    [ \t]*                 # 0 or more spaces and/or tabs (could be any number of both)
)
(                          # capturing group #2

    background:\s*-webkit-linear-gradient\(top\s*,\s*
    (                      # capturing group #3
        #[a-fA-F0-9]{3,6}  # a number sign and a string with 3 or 6 digits that's made of a-zA-Z0-9 (aka. hexadecimal characters)
    )
    \s*,\s*
    (                      # capturing group #4
        #[a-fA-F0-9]{3,6}
    )
    \s*\)\s*;
)
于 2013-01-17T15:09:58.627 回答
-1

我不明白正则表达式的原因。

为什么你不能找到:

background: -webkit-linear-gradient(top, #BBB, #999);

并替换为:

background: -ms-linear-gradient(top, #BBB, #999);background: -webkit-linear-gradient(top, #BBB, #999);

影子也一样……

于 2013-01-17T14:55:22.163 回答
-1

你为什么不只是制作“匹配案例”并使用“全部替换”/“替换”,看起来像:

情况1:

“寻找”

  background: -webkit-linear-gradient(top, #BBB, #999);

“代替”

  background: -ms-linear-gradient(top, #BBB, #999);    
  background: -webkit-linear-gradient(top, #BBB, #999);
于 2013-01-17T14:55:40.420 回答