Bash. regexp matching
<p>I'm developing a bash script and need some help with a complicated regexp... complicated to me at least!</p>

<p>I have some possible outputs with little variations after putting a card in monitor mode, and depending on the distro and the aircrack suite version, there are little variations. Some strings i need to parse are:</p>

<pre><code>(mac80211 monitor mode vif enabled for [phy0]wlan0 on [phy0]wlan0mon)
(mac80211 monitor mode vif enabled on [phy0]wlan0mon
(monitor mode enabled on wlanmon0)
(monitor mode enabled on wlanmon0
</code></pre>

<p>I need to take from these strings the new name of the interface... so wlan0mon in this case, but can be different depending of the card.</p>

<p>As you can see, sometimes there is final bracket ")" and sometimes there is not. And sometimes i have [something] and sometimes not. I need to take from "on " (note the space after on) till the end with these variations... I have an approach but no joy. It only works with strings having "]" and no idea of how to avoid against all the possibilities.</p>

<pre><code>[[ ${new_interface} =~ ^(.*)\]+([a-zA-Z0-9]+)\)?$ ]] &amp;&amp; new_interface="${BASH_REMATCH[2]}"
</code></pre>

<p>Any suggestion? thanks!</p>