Regex to add a character at nth position?

自作多情 提交于 2019-12-25 07:19:31

问题


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



来源:https://stackoverflow.com/questions/38624383/regex-to-add-a-character-at-nth-position

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!