String pw="pw:(abc)";//Maybe "pw:(12)","pw:(ab123)"...
pw=pw.replaceFirst("\\(.+\\)", "*");
//pw == result:pw:*
I want the results: pw:*****. (abc) must be * x 5
Asterisk in quantities equal to the length of the content is matched
Can I use String.replaceFirst or String.replaceAll only way to implementing it?
You can do this:
which will result in:
Edit: does not work if the password has p/w/: in it… will try to fix..
Edit #2: This turned out to be harder than I thought, had to go with another approach:
So, first find the String consisting of “({something})”. Then create a String consisting of the number of stars in this string. Then replace the string with the stars in the input.
Note: This does not work if the password or the text after the ) contains parantheses, but then again I doubt you will find a regex that does..