java - How to do a case-insensitive+trim the string for the below requirement -


i want regex expression trim()+case sensitive find , replace.

i want replace "abc xyz:" "" each time comes in input string. able case sensitive replacement this.

string result = value.replaceall("(?i)abc xyz:", ""); 

but condition fails when there space between abc , xyz.

abc xyz:---> expected result "" abc    xyz:---> expected result "" abc xyz   :---> expected result "" abc    xyz  :---> expected result "" 

edit

solution worked!!

string result = value.replaceall("(?i)abc\\s+xyz\\s*:", "");  

you can use as

var re = /(abc\s+xyz\s*:)/gmi;  var str = 'abc xyz:\nabc xyz:\nabc    xyz:\nabc xyz   :\nabc    xyz  :'; var subst = '';   var result = str.replaceall(re, subst); 

demo


Comments