Limit regex evaluation where possible