[np] Replace patterns with regexes for speed