Basically I need to retrieve data inside <> or {} blocks in a string in java.
The String may or may not contain a <> or {} tag.
The string might contain multiple <> or {} blocks.
Data inside the <> and {} blocks are basically variables or function names.
d1 = "1234";
d2 = "5678";
sampleString = "aaa<d1>aaa{d1}aaa<d2>aaa";
I need the result to be similar to something like this.
resultString = "aaa1234aaa4321aaa5678aaa";
thanks in advance. 🙂
EDIT
I should make note that the values inside the <> and {} blocks are dynamic.
I could have
sampleString = "aaa<d5>aaa{d1}aaa<d2>aaa";
meaning it would get the value d5 from a property/variable/parameter/etc.
I should have stated that from the start. :p
First, create a
Mapfor your values:Then, find all matches and replace them:
And again for the other pattern: