Regex to Find Four Open Brackets without a Closing Bracket -


i'm trying find places in .less files nested 4+ levels deep without being closed.

here i'm @ on rubular: http://rubular.com/r/a6uwyh0muv

and in case you'd prefer see example here on so:

ul {     width:100%;     li {         width: 25%;         {             color: @blue;             span {                 font-weight: normal;             }         }     } }  ul {     width:100%;     li {         width: 25%;         {             color: @blue;         }     } }  ul {     width:100%;     li {         width: 25%;     } }  ul {     width:100%; } 

the 1 want match first test string has 4 nested css properties.

through various experiments, i've been able close still end matching parts of strings shouldn't caught regex.

any appreciated.

.*?(?:\{[^}]*?){4}(.*?\})  .*? makes sure find first one, not necessary (?:\{[^}]*?) finds 4 opening brackets without closing ones (.*?\}) capturing group until first closing bracket. 

if that's not want, can modified.

solving request in comments:

.*?(?:\{[^}]*?){4}(.*?)\}  

will give text contained within brackets (font-weight: normal;). did remove closing bracket capturing group.

and

.*?(?:\{[^}]*?){3}(\n[^\n]*?\{.*?\}) 

will solve second request. note way hackish , don't think work under circumstances. recommend first one, or tinkering 1 bit.

as crashing in sublime test 2, i'm not sure if can -- it's working me!


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -