eslint-plugin-optimize-regex
eslint-plugin-optimize-regex copied to clipboard
Autofix breaks "match all" in multiline regexps
trafficstars
Cross-posted from https://github.com/sindresorhus/eslint-plugin-unicorn/issues/895, as both plugins have the same issue.
This regexp is autofixed like this:
- /lorem(?:.|\n)*?ipsum/m
+ /lorem[.\n]*?ipsum/m
This breaks the regex:
(.|\n)means "any character, including a newline character"[.\n]means "a period character or a newline character"
Instead, it should be fixed to [^], according to https://stackoverflow.com/a/16119722/451391:
- /lorem(?:.|\n)*?ipsum/m
+ /lorem[^]*?ipsum/m
I've opened an upstream issue: https://github.com/DmitrySoshnikov/regexp-tree/issues/217