java - Find position of substring within string with conditions -


given string

string foo = "if (bar = 10 ) {     if (foobar == 1)     {      }  }" 

i want find position of "if" not have "if" within opening , closing braces. example above, want know position of second "if" not first "if".

i know have use form of regex new regex , not sure how go it. accept non regex answer.

maybe pattern help

(\bif\b)[^{}]*{[^{}]*} 

demo


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -