java - Dealing with nested parenthesis in regex -


I want to match my regex when the maximum depth is the full set of nested brackets 5. My current code is working But there is a complexity of its terrible time and it takes a very long time for brackets.

  ^ ((\\ ((\\ ((\\ ((\\ ((\\ (\\)) * \\) (\\ (\\)) *) * \\)) * \\)) * (\\ ((\\ ((\\ ((\\ (\\)) * \\) (\\ (\\)) *) * \\)) * \\)) * \\)) *) $  

Example:

  string s = (() ()); Println (s.matches (...));  

-> Print right.

  string s = ())); Println (s.matches (...));  

-> Print is incorrect.

How can I change my current code so that it is not only more efficient but a little easier to read? Note that I want to do this in regex and I know that doing so with loops is very simple. Thanks!

If you are only looking for a maximum depth of 5 then you should regexp

< Pre> (\ ((((((((((* (* (* (*)) * *) * * * * * * * * * * *) * *

You can remove the result here

Here is some PEDO code as a bonus that you can use to generate this string

  var s = "_", depth = 5; while (depth> 0) {s = s.replace ("_", "(\\ (_ \\)) *") ; Depth--;} S = s.replace ("_", "");  

Now if your needs change and string s Easy to change a variable ( depth ) using the regexp to use


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -