I need some clever code to show me how to do this. I cannot use substring, split, etc because there is no specific character to search on. I thought about looping the String and reading each character and have numerous if statements to test, but hoping there is a simpler way of doing this.
String str = "'1_First Name'='1_Johns' AND '200_Age' > '30' OR '123_Dog:name' IS 'Bolt'";
Output needed: "'1'='1_Johns' AND '200' > '30' OR '123' IS 'Bolt'"
This is a Remedy Query string. The '1_First Name' is the column name and the '1_Johns' is the column value.
I appended the column names with the column id_ which then gives me for example: '1_First Name'.
In Remedy we can search on column name or column ID. However column names can be the same, but column id's are unique.
So that is why only some parts of the string must be manipulated and others not.
str = str.replaceAll("('\\d+)_[^']+'(?=\\s*([<>=!]|IS))", "$1'");
('\\d+)_[^']+'
is the match for every variable.(?=\\s*([<>=!]|IS))
for a following operator;
lookahead (?= ... )
with pattern \\s*([<>=!]|IS)
.This more or less distinguishes between variable and value, both having the same regular pattern.