java - Regex replace with increment -


i use mystring.replaceall("(chapter.*?)br","chapter **increment**");

i want paste **increment** instead of increment, don't have idea how can it.

i have next text:

chapter br

texttexttexta

chapter b345 br

texttexttextb345

chapter ab br

texttexttextab

it has like:

chapter 1 br

texttexttexta

chapter 2 br

texttexttextb345

chapter 3 br

texttexttextab

i have chapters different index. example, chapter , chapter b. i'm grabbing chapters regex , change unique chapter chapter + increment.

found solution:

int n = 0; pattern r = pattern.compile("(chapter.*?)<br />");  matcher m = r.matcher(filetoshow); while (m.find()) {     system.out.println("found value: " + m.group(0));     filetoshow = filetoshow.replaceall(m.group(0),"<chapter "+ ++n +">"); } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -