public static MaskedText maskInUrl ( String url ) { MaskedText result = new MaskedText ( ) ; result . setClearText ( url ) ; result . setText ( url ) ; result . setMasked ( null ) ; if ( url != null ) { Matcher urlMatcher = URL_PATTERN . matcher ( url ) ; if ( urlMatcher . find ( ) ) { Matcher pwdMatcher = PASSWORD_IN_URL_PATTERN . matcher ( url ) ; if ( pwdMatcher . find ( ) ) { result . setText ( pwdMatcher . replaceFirst ( PASSWORD_IN_URL_MASK ) ) ; String s = pwdMatcher . group ( ) ; // with leading ":" and trailing "@" result . setMasked ( s . substring ( 1 , s . length ( ) - 1 ) ) ; } } } return result ; }
Mask password in URL .