regexp matching fully reworked