Split up regexp logic