Java String Regex replacement -


sample input:

a:b a.in:b asds.sdsd:b a:b___a.sds:bc___ab:bd 

sample output:

a:replaced a.in:replaced asds.sdsd:replaced a:replaced___a.sds:replaced___ab:replaced 

string comes after : should replaced custom function. have done same without regex. feel can replaced regex trying extract string out of specific pattern.

for first 3 cases, it's simple enough extract string after :, couldn't find way deal third case, unless split string ___ , apply approach first type of pattern , again concatenate them.

just replace letters exists next : string replaced.

string.replaceall("(?<=:)[a-za-z]+", "replaced"); 

demo

or

if want deal digits, add \d inside char class.

string.replaceall("(?<=:)[a-za-z\\d]+", "replaced"); 

Comments