regex replacing at beginning of line in notepad++

a 夏天 提交于 2020-01-30 08:43:45

问题


for example I have txt with content

qqqqaa
qqss
ss00

I want to replace only one q at the beginning of line, that is to get

qqqaa
qss
ss00

I tried replace ^q in notepad++. But After I click replaceAll, I got

aa
ss
ss00

What is wrong? Is my regex wrong? What is the correct form?


回答1:


The issue is that Notepad++ Replace All functionality replaces in a loop using the modified document.

The solution is to actually consume what we need to replace and keep within one regex expression like

^q(q*)

and replace with $1.

The pattern will find a q at the beginning of the line and then will capture into Group 1 zero or more occurrences of q after the first q, and in the replacement part the $1 will insert these qs inside Group 1 back into the string.




回答2:


You can use ^q(.+) and replace with $1 if you also want to replace single q's.



来源:https://stackoverflow.com/questions/38451821/regex-replacing-at-beginning-of-line-in-notepad

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!