Issue
There are lots of replacement which needs to be done in my string , so I am thinking if we can get the regex instead of replacing every word manually, Is there any way we can replace any word with "\?" to "? ", sample is shown below can someone help me with the regex pattern
query = query.replaceAll("id\\?", "?");
query = query.replaceAll("name\\?", "?");
query = query.replaceAll("empid\\?", "?");
query = query.replaceAll("value\\?", "?");
Solution
Try this.
String query = "SELECT * FROM t WHERE id=id? AND name=name? AND empid=empid? AND value=value?";
query = query.replaceAll("\\w+\\?", "?");
System.out.println(query);
output:
SELECT * FROM t WHERE id=? AND name=? AND empid=? AND value=?
Answered By - user4910279
Answer Checked By - Katrina (JavaFixing Volunteer)