简体   繁体   English

Notepad++ - 正则表达式:替换每行中第一次出现的字符组

[英]Notepad++ - regex : replace first occurrence of a characters group in each line

Someone would know the regex expression can be used (in notepad++) in order to replace the first occurence of a characters group in each line?有人会知道可以使用正则表达式(在记事本++中)来替换每行中第一次出现的字符组?

eg:例如:

abcdefg//ijkl//m.
qsdflkj//sdqlmkf//jqsmdl.

to

abcdefg\\ijkl//m.
qsdflkj\\sdqlmkf//jqsmdl.

so replace // by \\\\ in each line, but only the first occurence of , not the next.所以在每一行中用\\\\替换// ,但只有第一次出现,而不是下一次。

If regex can't achieve it, is there another method with notepad.如果正则表达式不能实现,记事本是否有另一种方法。 If not, I will code a program to split line and do the job, but need more time.如果没有,我将编写一个程序来分割线并完成这项工作,但需要更多时间。

Thnaks in advance.提前谢谢。

Enter this regex in Find what fieldFind what字段中输入此正则表达式

(.*?)//(.*)

Enter this in Replace with fieldReplace with字段中输入此内容

$1\\$2

Select Regular expression in Search Mode and Uncheck . matches newlineSearch Mode选择Regular expression并取消选中. matches newline . matches newline

  • Ctrl + H Ctrl + H
  • Find what: ^[^/]+\\K//找到什么: ^[^/]+\\K//
  • Replace with: \\\\\\\\替换为: \\\\\\\\
  • check Wrap around检查环绕
  • check Regular expression检查正则表达式
  • Replace all全部替换

Explanation:说明:

^               : begining of line
  [^/]+         : 1 or more any character that is not a slash
  \K            : forget all we have seen until this position
  //            : 2 slashes

Replacement:更换:

\\\\     : 2 backslashes, each one must be escaped

Result for given example:给定示例的结果:

abcdefg\\ijkl//m.
qsdflkj\\sdqlmkf//jqsmdl.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM