plugin-regexp/remove-useless-group should not remove groups in `.split()` or `.replace()`
See original GitHub issueIssue Description
plugin-regexp/remove-useless-group changes:
'lala'.split(/(a)/g); // Output: ["l", "a", "l", "a", ""]
into:
'lala'.split(/a/g); // Output: ["l", "l", ""]
It also changes:
'lala'.replace(/(a)/g,'-$1-'); // Output: "l-a-l-a-"
into:
'lala'.replace(/a/g,'-$1-'); // Output: "l-$1-l-$1-"
This plugin is safe to use in .test()
, but should likely ignore regex that appears in any other function (match, split, replace).
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Replace ignores non-capture group - regex - Stack Overflow
Regardless of whether you create a capture or not, .Replace() will always replace the whole match. From MSDN: Regex.Replace Method (String ...
Read more >Capturing groups - The Modern JavaScript Tutorial
Method str.replace(regexp, replacement) that replaces all matches with regexp in str allows to use parentheses contents in the replacement ...
Read more >SplitChunksPlugin - webpack
Webpack will automatically split chunks based on these conditions: New chunk can be shared OR modules are from the node_modules folder; New chunk...
Read more >Searching - Notepad++ User Manual
Searching. There are multiple methods to search (and replace) text in files. You can also mark search results with a bookmark on their...
Read more >perlretut - Perl regular expressions tutorial - Perldoc Browser
The first regexp world doesn't match because regexps are by default case-sensitive. The second regexp matches because the substring 'o W' occurs in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Wonderful, now works correctly when inside of a split or replace. There are three other situations I’ve been able to find where this results in changing the output:
A possible solution (in particular to the standalone regex) might be to whitelist regex that is:
instead of blacklisting?
(By the way, this is a great project that I’ve been much in need of!)
Landed in
@putout/plugin-regexp@2.8.0
🎉 . Is it works for you?