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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -