Add a detection mode
Replace hardcoded "\n" with os.linesep
Use regular erxpression matching whenever possible