Kaah
Kaah

Reputation: 1201

Replace regexp capture-group in Notepad++?

Quick question: I have a regexp, ^(?:\b[A-Z]+\b\s+)+(.*)\d{8}, that gives two capture groups. I would like to replace capture group 1 with a whitespace. Is that possible?

If I do replace with: \1 it replaces TEST TESTER Hello, world. Another word here. 75793250 -> with Hello, world. Another word here. I want this result: TEST TESTER 75793250. Replacing the \1 with a whitespace.

Upvotes: 100

Views: 99309

Answers (3)

Marcel Schmitz
Marcel Schmitz

Reputation: 11

Building Groups with (?<1>....),(?<2>....), for substitution using \1 \2

Upvotes: 1

Anirudha
Anirudha

Reputation: 32797

Do it this way:

Regex: ^(\b[A-Z]+\b\s+)+(?:.*)(\d{8})

Replace with: \1 \2

Upvotes: 14

Jerry
Jerry

Reputation: 71538

Try using:

^((?:\b[A-Z]+\b\s+)+)(?:.*)(\d{8})

And replace with:

\1\2

Upvotes: 168

Related Questions