Regex to add a character at nth position?

2019-09-12 14:23发布

问题:

I have this text:

1111111111111111111111111111111111111111111111111

where I need to add character at fifth position to have this result

11111A11111111111111111111111111111111111111111111

I tried with

(?<=.{5})

Replace with

A

it puts A after fifth character but continue to ad to every next five characters.

I am using Powergrep. How to make it to stop after first occurence?

回答1:

You could use the ^ character to anchor the regular expression to the start of the string:

(?<=^.{5})

See regex tester



标签: regex replace