Reputation: 8675
I have some text like this:
1|Some things|US|192||||||1||
2|Some other things|US|128|3|||5|1|1|3|
3|Whatever else|US|128||15||||||
And I'd like to replace it in Notepad++ with something like:
1|Some things|US|192|+++++1++
2|Some other things|US|128|3+++5+1+1+3+
3|Whatever else|US|128|+15++++++
But I couldn't find some proper way to do it. I managed to build a RegExp that matches the string:US\|(\d+)\|((\d*)\|)+
but I couldn't find how to build the replacement string to match this group-of-groups approach.
The hard part for me was excluding the first number after the "US". The only way out I could see was replacing (?<![a-zA-Z])\|(?![a-zA-Z])
for +
and then replacing US\|(\d+)\+
back to US|\1|
.
Is it possible to do such a replacement with Notepad++'s builtin or TextFX's replacement tools?
Upvotes: 2
Views: 475
Reputation: 89557
You can use this pattern:
(?:\G(?!^)|\|US\|\d+\|)\d*\K\|
With +
as replacement string.
For each line the scenario is the same:
\|US\|\d+\|
and match the first pipe\G
anchor that ensures the contiguity.The \K
feature removes all previous matched characters from the match result and only the pipe is replaced.
Upvotes: 4