Extract IPs before string <p>I have this text:</p> <pre><code>111.11.1.111(*)222.22.2.221(mgn)333.33.3.333(srv) 111.11.1.111(*)333.33.3.333(srv)222.22.2.222(mgn) 222.22.2.223(mgn)111.11.1.111(*)333.33.3.333(srv) </code></pre> <p>I only want to know the IP's before (mgn), output:</p> <pre><code>222.22.2.221 222.22.2.222 222.22.2.223 </code></pre> <p>thanks</p>