Question: As a premise, I have an HTML text, with some `<ol>` elements. These have a `start` attribute, but the framework I'm using is not capable to interpret them during a PDF conversion. So, the trick I am trying to apply is to add a number of invisible `<li>` elements at the beginning.

As an example, suppose this input text:

```
<ol start="3">
   <li>Element 1</li>
   <li>Element 2</li>
   <li>Element 3</li>
</ol>

```

I want to produce this result:

```
<ol>
   <li style="visibility:hidden"></li>
   <li style="visibility:hidden"></li>
   <li>Element 1</li>
   <li>Element 2</li>
   <li>Element 3</li>
</ol>

```

So, adding n-1 invisible elements into the ordered list.
But I'm not able to do that from Java in a generalized way.

Supposing the exact case in the example, I could do this (using `replace`, so - to be honest - without regex):

```
htmlString = htmlString.replace("<ol start=\"3\">",
            "<ol><li style=\"visibility:hidden\"></li><li style=\"visibility:hidden\"></li>");

```

But, obviously, it just applies to the case with "start=3". I know that I can use groups to extract the "3", but how can I use it as a "variable" to specify the string `<li style=\"visibility:hidden\"></li>` n-1 number of times?
Thanks for any insight.

Answer: 
Using Jsoup you can write something like: 

```
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

class JsoupTest {
    public static void main(String[] args){
        String html = "<ol start=\"3\">\n" +
                        "   <li>Element 1</li>\n" +
                        "   <li>Element 2</li>\n" +
                        "   <li>Element 3</li>\n" +
                        "</ol>"
                + "<p>some other html elements</p>"
                + "<ol start=\"5\">\n" +
                        "   <li>Element 1</li>\n" +
                        "   <li>Element 2</li>\n" +
                        "   <li>Element 3</li>\n" +
                        "   <li>Element 4</li>\n" +
                        "   <li>Element 5</li>\n" +
                        "</ol>";

        Document doc = Jsoup.parse(html);
        Elements ols = doc.select("ol");
        for(Element ol :ols){
            int start = Integer.parseInt(ol.attr("start"));
            for(int i=0; i<start-1; i++){
                ol.prependElement("li").attr("style", "visibility:hidden");
            }  
            ol.attributes().remove("start");
            System.out.println(ol);
        }
    }
}

```
***You can try this.***

```
String input="<ol    start=\"6\">"+
   "<li>Element 1</li>"+
   "<li>Element 2</li>"+
   "<li>Element 3</li>"+
   "<li>Element 4</li>"+
   "<li>Element 5</li>"+
   "<li>Element6</li>"+
"</ol>";

 Matcher match= Pattern.compile("<ol .*start.*=.*\\\"(.*)\\\"\\s*>(.*)(</ol>)").matcher(input);
    String resultString ="";
    if(match.find()){
    resultString =match.replaceAll("<ol>"+new String(new char[Integer.valueOf(match.group(1))-1]).replace("\0", "\n\t<li style=\"visibility:hidden\" />")+"$2$3");  

}

```