improved regexp matching