Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split encrypted text within brackets in java

Tags:

java

regex

I have encrypted text wraped with brackets, i'm trying to get only the text [|kXS6k~R5I~Q5gHR&f3gzJ[X] -->|kXS6k~R5I~Q5gHR&f3gzJ[X
Found this pattern [\[\](){}] , it works but split until first brackets or if there are parenthesesit will split the text untill them . thanks

like image 947
Maor Avatar asked Oct 01 '16 11:10

Maor


1 Answers

You can try this: "\[(.*?)\]". And don't forget to have the backslash escaped in your string otherwise it will give you error

String string = "[AA{R7QHQ8onQ~QXR7UXQzM\e{J6Y]";

String regex = "\\[(.*?)\\]";
String string = "[AA{R7QHQ8onQ~QXR7UXQzM\\e{J6Y]";

Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(string);

while (matcher.find()) {
    System.out.println("Full match: " + matcher.group(0));
    for (int i = 1; i <= matcher.groupCount(); i++) {
        System.out.println("Group " + i + ": " + matcher.group(i));
    }
}
like image 163
Rizwan M.Tuman Avatar answered Oct 06 '22 10:10

Rizwan M.Tuman