java - Get substring in a string with multiple occurring string -


i have string

(d@01)5(d@02)14100319530033m(d@03)1336009-a-a(d@04)141002a171(d@05)1(d@06) 

now want substring between (d@01)5(d@02)

if have

(d@01)5(d@02) 

i can detail with

    quantity         = content.substring(content.indexof("(d@01)") + 6, content.indexof("(d@02)")); 

but somethings d@02 can different @05, how can use simple (d@ string in between. there multiple repetitions of (d@

basically want do

content.substring(content.indexof("(d@01)") + 6, content.nextoccurringindexof("(d@")); 

i suppose can do

int fromindex = content.indexof("(d@01)") + 6; int toindex = content.indexof("(d@", fromindex);    // next occurring  if (fromindex != -1 && toindex != -1)     str = content.substring(fromindex, toindex); 

output

5 

see http://ideone.com/rrutby demo.


Comments