Notepad ++正则表达式从行开始查找和替换2个字符,但以它开头


0

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

我需要用逗号分隔的多行替换一些数据。但它应该跳过开头的行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
我真的没有得到输入和输出之间的区别。请编辑您的问题并添加更多输入行,混合可修改和不可修改,(格式正确)和预期结果(格式正确)
Toto

当然,请给我片刻
Tammys Head

好的,这应该会好得多。
Tammys Head

Answers:


0
  • 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

太棒了!非常感谢你!还要感谢解释!^^
Tammys Head

@TammysHead:欢迎你,很高兴它有所帮助。
托托于
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.