-1

How can i find out words from a string that contain special char Ex:

String sqlQuery="INSERT INTO TABLE(ID) VALUES(#ABC_11#),(#ABCDE_12#)";

o/p:

ABC_11
ABCDE_12
Roshana Pitigala
  • 7,945
  • 8
  • 47
  • 71
mukta
  • 11
  • 4

2 Answers2

1

try this

String sqlQuery="INSERT INTO TABLE(ID) VALUES(#ABC_11#),(#ABCDE_12#)";
        Matcher matcher = Pattern.compile("#(.*?)#").matcher(sqlQuery);
        while (matcher.find()) {
            System.out.println(matcher.group().replaceAll("#",""));
        }

Output

ABC_11
ABCDE_12
soorapadman
  • 4,343
  • 6
  • 34
  • 45
0

You need to clean your input names first.
This might help you:

//your dirty name inputs
String dirty_name = "#ABC_11#"

//removes special characters like [~!@#$%^&*()-=+]
String name = dirty_name.replace('[^\w]','')

//put in your query
String sqlQuery="INSERT INTO TABLE(ID) VALUES("+name+")"