I'm developing a bash script and need some help with a complicated regexp... complicated to me at least!
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:
(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
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.
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.
[[ ${new_interface} =~ ^(.*)\]+([a-zA-Z0-9]+)\)?$ ]] && new_interface="${BASH_REMATCH[2]}"
Any suggestion? thanks!
This will be much simpler
[[ ${new_interface} =~ \]?([A-Za-z0-9]+)\)?$ ]] && new_interface="${BASH_REMATCH[1]}"