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

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -