Skip to content

Instantly share code, notes, and snippets.

@vanjikumaran
Created April 25, 2019 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanjikumaran/ac1f03c7549a2935201c093ff7aea1d8 to your computer and use it in GitHub Desktop.
Save vanjikumaran/ac1f03c7549a2935201c093ff7aea1d8 to your computer and use it in GitHub Desktop.
Regex based Char replacement.
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class RegexBasedTest {
private static final Pattern PASSWORD_PATTERN = Pattern.compile("[a-zA-z0-9]{3}");
private static final String uuid = "b02fb649-797b-440b-9aa9-f3294ed0ce73";
public static void main(String[] args) {
for (int i = 0; i < Integer.MAX_VALUE; ++i) {
String masked = replaceChar(uuid);
}
}
private static String replaceChar(String uuid) {
final Matcher pwdMatcher = PASSWORD_PATTERN.matcher(uuid);
return pwdMatcher.replaceFirst("****");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment