简体   繁体   中英

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

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...

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

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

search for

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

replace with

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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