 <blockquote> <p>I want to split it, so that each html element be a separate string.</p> </blockquote> <p>Here is an alternative answer using the <code>split()</code> method only. (ie no delimiter needed). Note that with this solution, text with blank characters only are preserved.</p> <h3>SAMPLE CODE</h3> <pre><code>String str = "&lt;form action=''&gt;&lt;span&gt; First Name &lt;/span&gt; &lt;input type='text' id='fname' class='cls' size='40' required /&gt; &lt;span&gt; [*]&lt;/span&gt; &lt;input type='submit' value='Submit' name='btn' /&gt; &lt;select name='slcEle' &gt; &lt;option value='opt'&gt; Text&lt;/option&gt; &lt;/select&gt; &lt;input type='radio' id='this'/&gt; &lt;button name='name' type='reset' value='val'&gt; Text&lt;/button&gt; &lt;input type='range' min='0' max='100' name='grade'/&gt; &lt;button name='btnname' type='button'&gt; Text&lt;/button&gt;"; String[] separateStrings = str.split("(?&lt;=&gt;)|(?=&lt;/)"); int len = separateStrings.length; for (int i = 0; i &lt; len; i++) { System.out.format("[%d] = %s\n", i, separateStrings[i]); } </code></pre> <h3>OUTPUT</h3> <pre><code>[0] = &lt;form action=''&gt; [1] = &lt;span&gt; [2] = First Name [3] = &lt;/span&gt; [4] = &lt;input type='text' id='fname' class='cls' size='40' required /&gt; [5] = &lt;span&gt; [6] = [*] [7] = &lt;/span&gt; [8] = &lt;input type='submit' value='Submit' name='btn' /&gt; [9] = &lt;select name='slcEle' &gt; [10] = &lt;option value='opt'&gt; [11] = Text [12] = &lt;/option&gt; [13] = [14] = &lt;/select&gt; [15] = &lt;input type='radio' id='this'/&gt; [16] = &lt;button name='name' type='reset' value='val'&gt; [17] = Text [18] = &lt;/button&gt; [19] = &lt;input type='range' min='0' max='100' name='grade'/&gt; [20] = &lt;button name='btnname' type='button'&gt; [21] = Text [22] = &lt;/button&gt; </code></pre>