 <p>You could simply use grep instead of <code>sed</code> . The reason why i choose <code>grep</code> means, grep is a tool which prints each match in a separate line.</p> <pre><code>grep -oP 'tel:\K.*?(?=;)' file.txt </code></pre> <p><strong>Regular Expression:</strong></p> <pre><code>tel: 'tel:' \K '\K' (resets the starting point of the reported match) .*? matches any character except \n (0 or more times) non-greedily (?= look ahead to see if there is: ; ';' ) end of look-ahead </code></pre> <p><strong>Update:</strong></p> <pre><code>$ cat file tel:02134343, 3646848393; tel:02134343; tel:02134344; $ grep -oP '(?:tel:|(?&lt;!^)\G)\K\d*(?=[^;\n]*;)' file 02134343 3646848393 02134343 02134344 </code></pre>