How do I get the required output?
input string :
" software Company(1920 of 2012)(sb.2)(sb.3) IBM on established (2009)"
word to be searched –
"software company(1920 of 2012)"
Output
*software Company(1920 of 2012)*(sb.2)(sb.3) IBM on established (2009)
In short I have to find a phrase and replace the same phrase with starting and ending with asterisk (*), IGNORING THE CASE, and MATCH EXACT WORLD i
You can do this easily using
String#replaceAll():The
(?i)is added to make it case insensitive, and thePattern#quote()is used to escape special regex characters in your substring.This prints: