eslint-plugin-optimize-regex icon indicating copy to clipboard operation
eslint-plugin-optimize-regex copied to clipboard

Autofix breaks "match all" in multiline regexps

Open FloEdelmann opened this issue 5 years ago • 1 comments
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

FloEdelmann avatar Nov 05 '20 17:11 FloEdelmann

I've opened an upstream issue: https://github.com/DmitrySoshnikov/regexp-tree/issues/217

FloEdelmann avatar Jan 12 '21 12:01 FloEdelmann