-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
  • 8,437
  • 8
  • 49
  • 80
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,451
  • 7
  • 35
  • 47
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+")"
Nagesh Mhapadi
  • 152
  • 3
  • 14