varstr='this is photo1 and photo2 and photo3';
Java’s replace method is not ideal for noobs but only for people who know about regex. I am not that quite familiar with regex and if you wish to use that replace method under the String class in Java, you’d have to familiarize yourself with it in order to use it. The String class though, has lots of other useful methods that can be used to simulate how a search and replace function works. Here is a workaround method for people who only want a simple search and replace with the search and target both String. No regex knowledge needed.
The method replaceString returnsaStringandtakes in3parameters.First would be the original stringwhere you want your search andreplace totake place into.Second isbe the stringtosearch forandthird isthe replace string.
varstr='this is a string';
The replace function contains two options. ‘i’ means the search would be case insensitive and ‘g’ means global, meaning it will search all instances of the search string within the str variable. If you do not include ‘g’ as its option, then only the first instance of the search string will be replaced.