The repeating characters can be anything [a to z], [0 to 9] or any special characters.
For example:
String a = "CCCCCCgshdbuasvbd";
Consider C = [a to z],[0 to 9], or anything like ~!@#$%*&()_-><?.
I need to remove the "any repeating leading characters in string if that occurs more than 4 times" in the string.
How can I accomplish this using a regex?
You can use:
str = str.replaceAll("^(\\S)\\1{3,}", "");
How about:
Search: ^(.)\1{3,}
Replace: <NOTHING>
This will replace any character at the beginning of the string, present 4 or more times, by nothing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With