3 Replies Latest reply: Nov 27, 2013 1:16 PM by Hugo Tigre RSS

    Regex pattern, filter delimiter in sql code

    Hugo Tigre



      The problem I'm having is that the regex pattern below is not catching the beginning "go" and ending "go" of a string.




      The idea is catching the "whole word", in this case the word is "go" so if the word is at the beginning of the string or at the end, i still want to include it.

      So, for example:

      "go select * from table1 go" -> should catch 2 "go"s but catches 0

      "go go# select * from table1 --go go" -> should also catch 2 "go"s but catches 0

      "go go select * from table1 go go" -> should catch 4 "go"s but catches 2


      I have the "[(?<=\\s)]" and the "(?=\\s)" so that the word "go" when next to a special character is not included, for example "--go".


      The problem is that this also negates the beginning and ending of the string.


      Code to test example: It should split at 1st, 2nd and last "go", but only splits at the 2nd "go".

      String s = "go go select * from table1 --go go";
      String delimiter = "go";
      String[] queries = s.split("(?iu)[(?<=\\s)]\\b" + delimiter + "\\b(?=\\s)");
      for (int i = 0; i < queries.length; i++) {


      I really need to fix this but I'm not having much success.


      Any help will be appreciated, thanks in advance.