Alecos
Alecos

Reputation: 57

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

Upvotes: 0

Views: 933

Answers (3)

amiregelz
amiregelz

Reputation: 1845

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

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

Upvotes: 2

John Corbett
John Corbett

Reputation: 1615

search for

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

replace with

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

Upvotes: 1

Lars Knickrehm
Lars Knickrehm

Reputation: 747

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.

Upvotes: 0

Related Questions