Notepad++ 正则表达式查找并替换行中的 2 个字符,但以以下字符开头的除外

Notepad++ 正则表达式查找并替换行中的 2 个字符,但以以下字符开头的除外

所以我是正则表达式的新手,在这里遇到了这个问题。

我需要替换多行中以逗号分隔的某些数据。但它应该跳过以 开头的行Style: sign

例子:

这些是数据的含义(用逗号分隔,只是为了显示其代表什么)。

Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding

需要替换的东西是:(Bold替换为 0)和ScaleX(替换为 85)

这是需要替换一些内容的整段文本。

Style: main,Arial,23,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,1.35,0,2,10,10,20,1
Style: italics,Arial,23,&H00FFFFFF,&H000000FF,&H004E2C2A,&H00000000,-1,-1,0,0,100,100,0,0,1,1.35,0,2,10,10,20,1
Style: sign_1330_2_K_a_t_a_g_i_r_i_,Trebuchet MS,12,&H00C1D8BF,&H000000FF,&H004D973B,&H00000000,-1,0,0,0,100,100,0,17,1,3,0,8,30,375,80,1
Style: sign_1446_5_K_a_g_a_r_i___A_,Trebuchet MS,12,&H00F1FBE9,&H000000FF,&H004F963D,&H00000000,-1,0,0,0,100,100,0,-15,1,3,0,2,335,30,100,1
Style: sign_2051_16_M_a_t_s_u_o___M_,Trebuchet MS,12,&H00C1D8BF,&H000000FF,&H004D973B,&H00000000,-1,0,0,0,100,100,0,7,1,3,0,8,162,468,64,1
Style: sign_2163_16_Schleich,Times New Roman,16,&H0021110C,&H000000FF,&H007D594A,&H00000000,-1,0,0,0,100,100,0,-10,1,3,0,8,67,507,25,1

结果应该是这样的:

Style: main,Arial,23,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,85,100,0,0,1,1.35,0,2,10,10,20,1
Style: italics,Arial,23,&H00FFFFFF,&H000000FF,&H004E2C2A,&H00000000,0,-1,0,0,85,100,0,0,1,1.35,0,2,10,10,20,1
Style: sign_1330_2_K_a_t_a_g_i_r_i_,Trebuchet MS,12,&H00C1D8BF,&H000000FF,&H004D973B,&H00000000,-1,0,0,0,100,100,0,17,1,3,0,8,30,375,80,1
Style: sign_1446_5_K_a_g_a_r_i___A_,Trebuchet MS,12,&H00F1FBE9,&H000000FF,&H004F963D,&H00000000,-1,0,0,0,100,100,0,-15,1,3,0,2,335,30,100,1
Style: sign_2051_16_M_a_t_s_u_o___M_,Trebuchet MS,12,&H00C1D8BF,&H000000FF,&H004D973B,&H00000000,-1,0,0,0,100,100,0,7,1,3,0,8,162,468,64,1
Style: sign_2163_16_Schleich,Times New Roman,16,&H0021110C,&H000000FF,&H007D594A,&H00000000,-1,0,0,0,100,100,0,-10,1,3,0,8,67,507,25,1

以 开头的行Style: sign应该保持不变,就像我之前写的那样。也可以用两个或多个命令来完成。不必是一行。

有人能帮我吗?

答案1

  • Ctrl+H
  • 找什么:^Style:\h+(?:(?!sign)[^,]+,){7}\K-?\d+((?:,[^,]+){3}),-?\d+
  • 用。。。来代替:0$1,85
  • 检查环绕
  • 检查正则表达式
  • Replace all

解释:

^               # beginning of line
  Style:        # literally
  \h+           # 1 or more horizontal spaces
  (?:           # start non capture group
    (?!         # negative lookahead, make sure we haven't
      sign      # literally
    )           # end lookahead
    [^,]+       # 1 or more non comma
    ,           # 1 comma
  ){7}          # end group, must appear 7 times
  \K            # forget all we have seen until this position
  -?            # optional minus sign
  \d+           # 1 or more digits
  (             # start group 1
    (?:         # start non capture group
      ,         # 1 comma
      [^,]+     # 1 or more non comma
    ){3}        # end group, must appear 3 times
  )             # end group 1
  ,             # 1 comma
  -?            # optional minus sign
  \d+           # 1 or more digits

替代品:

0           # zero
$1          # content of group 1
,           # a comma
85          # 85

给定示例的结果:

Style: main,Arial,23,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,85,100,0,0,1,1.35,0,2,10,10,20,1
Style: italics,Arial,23,&H00FFFFFF,&H000000FF,&H004E2C2A,&H00000000,0,-1,0,0,85,100,0,0,1,1.35,0,2,10,10,20,1
Style: sign_1330_2_K_a_t_a_g_i_r_i_,Trebuchet MS,12,&H00C1D8BF,&H000000FF,&H004D973B,&H00000000,-1,0,0,0,100,100,0,17,1,3,0,8,30,375,80,1
Style: sign_1446_5_K_a_g_a_r_i___A_,Trebuchet MS,12,&H00F1FBE9,&H000000FF,&H004F963D,&H00000000,-1,0,0,0,100,100,0,-15,1,3,0,2,335,30,100,1
Style: sign_2051_16_M_a_t_s_u_o___M_,Trebuchet MS,12,&H00C1D8BF,&H000000FF,&H004D973B,&H00000000,-1,0,0,0,100,100,0,7,1,3,0,8,162,468,64,1
Style: sign_2163_16_Schleich,Times New Roman,16,&H0021110C,&H000000FF,&H007D594A,&H00000000,-1,0,0,0,100,100,0,-10,1,3,0,8,67,507,25,1

相关内容