Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Regex pattern, filter delimiter in sql code

Hugo TigreNov 27 2013 — edited Nov 27 2013

Hi,

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

"(?iu)[(?<=\\s)]\\bgo\\b(?=\\s)"

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++) {

     System.out.println(queries[i]);

}

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

Any help will be appreciated, thanks in advance.

This post has been answered by Hugo Tigre on Nov 27 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 25 2013
Added on Nov 27 2013
3 comments
924 views