I need to match or replace a part of string like below, but I couldn't write the exact regular expression for that in java.
String:
text1${text2${text3}text4}text5
Expected regex should match the test3 alone, ie. anything inside "inner" ${}. Above example has an outer ${...} and an inner ${...}, like ...${...${...}...}.... And test3 is inside the "inner ${} which is what I want.
The following regex captures the entire content within ${...}, not just the content of "inner" ${...}
\$\{(.*?)\}
More Examples:
text1${text2${text3}text4}text5 - match "text3"
text1text2${text3}text4text5 - should not match anything
text1${text2${text3}text4text5 - should not match anything
Update:
text1${text2${text3}${text4}text5} - match "text3" and "text4"