0

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

0

3 Answers 3

2

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

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

Sign up to request clarification or add additional context in comments.

4 Comments

+1. Ignore the other answers that tell you to use the $ to for match replacement -- Notepad++ doesn't support that. I suspect they don't use Notepad++, which uses the backslash: \1, as amiregelz shows you here.
@Faust Apparently, Notepad++ does support $ for referencing regex groups.
@JohnCorbett: OK, you're right. I just upgraded my version of Notepad++ and found that it works now. Must be a recent change.
Yes, Notepad++ only supported standard POSIX Regular Expressions in the past, but they added full PCRE (Perl Compatible Regular Expression) Search/Replace support in one of their latest versions. PCRE's is more powerful and flexible than the POSIX regex.
1

search for

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

replace with

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

2 Comments

$1 does not represent first group in notepad++. It is \1
Worked fine! more of 530 files replaced. Thanks to all people for helping me.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.