-1

I have a string in java Select * from tbl_Name tn where tn.PublicID='?'and I am trying to find the occurrence of .PublicID='?' considering case insensitivity.

I am using below regex expression (?i).PublicID[ ]?=\'\?\', but it is not able to find any match in above string

Java Snippet used

String query = "";
                    if(queryOrTable.equalsIgnoreCase("Query"))
                    {
                        Pattern pattern = Pattern.compile("(?i).PublicID[ ]?=\\'\\?\\'");

                        Matcher matcher = pattern.matcher(tblName);
                        if(matcher.matches())
                        {
                            query = query.replaceAll("(?i).PublicID[ ]?=\\'\\?\\'", ".PublicID='" + publicID + "'");
                        }
                        else
                        {
                            System.out.println("malformed query");
                        }
                    }
DevX
  • 490
  • 6
  • 23

1 Answers1

-1

That should work.

Tested here: https://www.freeformatter.com/java-regex-tester.html

Now, instead of [ ]? matching one space, I'd use \s*.

You are matching one optional space with yours, I'm saying match 0 or more whitespace characters (which will work for more cases of SQL than what you're looking for.

mikeb
  • 10,578
  • 7
  • 62
  • 120