How can I replace HTML code in Notepad++ using RegEx

一个人想着一个人 提交于 2019-12-24 19:43:01

问题


I have a lot of php pages. Every php page has inside a string like this:

<FONT COLOR="#0000FF">Post ID: 16107</FONT>

and I'd like to replace with:

<A HREF="#16107">Post ID: 16107</A>

but since every php page has a different Post ID and I'd like to match every occurrence of the string... I use as usually notepad2 witch supports regex and notepad++ too that supports regex as well. How can I replace all strings into all files into all dirs? Are about 350 files...


回答1:


Replace: <FONT COLOR=".*?">(Post ID: ([0-9]+))</FONT>

With: <A HREF="#\2">\1</A>




回答2:


search for

<FONT COLOR=".*?">Post ID: (\d+)<\/FONT>

replace with

<A HREF="#$1">Post ID: $1<\/A>




回答3:


Good to know this is possible:

In Notepad++ you'd need to search for Keep ID: ([0-9]*) and replace it with New ID: $1.

  • $0 represents the whole thing found, $1 the first found in brackets.
  • you can use [] to create a class (in this case of numbers 0 to 9)
  • and finally the asterisk tells the parser to repeat the previuos character or character class as often as possible.


来源:https://stackoverflow.com/questions/11847147/how-can-i-replace-html-code-in-notepad-using-regex

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