1

I have String

String myData = "status:\" op en \" AND \"Managed Type\":\"El ectrical\" AND status:verified status:\"resolved\" OR Managed Type:\"Ci vil\"";

I need to distinct all values and attributes from the string.

I have tried one regex with pattern which fulfill requirement as some level , but need help for complex parsing

Pattern pattern = Pattern.compile(
                "\\s*[OR|AND]?\\s*(\"?[[\\s*]?\\w*[\\s*]?]*\"?)\\:\"?(([\\s*\\(\\)<>/\\\\\\$\\=\\#\\+%^'`&!{}:;|\\?\\*\\.\\[\\],~@-]?\\w*[\\(\\)<>/\\\\\\$\\=\\#\\+%^'`&!{}:;|\\?\\*\\.\\[\\],~@-]?\\s*)*)\"?\\s*[OR|AND]?\\s*",
                Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(mydata);
        while (matcher.find()) {
            System.out.println(matcher.group(1) + " : " + matcher.group(2));
        }

OutPut is like that

status :  op en 
"Managed Type" : El ectrical
D status : verified status:
" OR Managed Type : Ci vil

Accepted result

status :  op en 
"Managed Type" : El ectrical
status : verified 
status: resolved
Managed Type : Ci vil

Thanks in advance.

Mayur Raval
  • 3,250
  • 6
  • 34
  • 57

1 Answers1

0

I had same issue and I tried following regular expression string which is working fine (please note that I tried in iOS):

NSString *regExPattern = @"(\\w*|\"[\\w\\s]{1,}\"):(\"[\\w\\s]{1,}\"?|\\w*)";
Premal
  • 551
  • 1
  • 6
  • 25