How to add characters in front of a string up to a certain length with RegEx .
For example, I have this text string and I want to add a # in front of it until the total length of the string is 12 .
cadena ---> ######cadena
I can't find a way to know how many # to put in front of it to reach the desired length.
(.{0,6})
#########$1
As you mention that you can apply several regular expressions, I would do it with two.
The first will take care of adding
#
enough grids and the second will remove unnecessary grids.For example, given the string
123456
The first regular expression would be:
Find:
^(.*)$
Replace with:############\1
So the text would be:
############123456
Then to the previous result we apply the second regular expression:
Find:
^.*?(.{12})$
Replace with:\1
It would look like this:
######123456
I leave you a demo of the first and the second regular expression.