I need to replace d+ and a+ to x, I want to replace all the d+ to x, but for a+, I only want to replace the first occurance if there's any.
d+
a+
x
Is it possible to use only one regex to achieve this?
123,456,789
x,x,x
123,456,a,789
x,x,x,x
aaa,aa,aaa
x,aa,aaa
aa,123,456,aaaa,789
x,x,x,aaaa,x
aaa,123,456,aa,789,aaaa
x,x,x,aa,x,aaaa
Sorry I forget that answer must be posted aside and post it in comments at first.
Now here it is:
Regex: d+|((?<!a|(?!(?1)).))a+
d+|((?<!a|(?!(?1)).))a+
Replacement: x
https://regex101.com/r/v24o7B/1
2.1m questions
2.1m answers
60 comments
57.0k users