change your * to \{-}: #bad (.*?) #good (.\{-}) Post navigation Automate key and mouse events in Linux (xev/xdotool)New server