firasdib / Regex101

This repository is currently only used for issue tracking for www.regex101.com
3.21k stars 198 forks source link

Code Generator: sed should not append ;d #2116

Closed OnlineCop closed 11 months ago

OnlineCop commented 11 months ago

Bug Description

The Code Generator for SED appends ;d which is deleting non-matching lines. Without the ;d at the end, non-matching lines are preserved.

Reproduction steps

Example code, where substitution is empty to simply remove the text at the end of the lines: https://regex101.com/r/HNAF9L/1 Code Generator with SED selected: https://regex101.com/r/HNAF9L/1/codegen?language=SED

Current output:

$ sed -E 's/-[0-9][0-9]*(\.[0-9][0-9-]*|\.[a-z0-9][a-z0-9]*)*//gm;t;d' <<< "no-match
keep-only-this-text-1.1.2-7.el7.noarch
no-match-1.4.8-3.el7_4.1.i686
keep-this-text-1.4.8-3.el7.1.x86_64
match-1.4.8-3.el7_2.1.x86_64
no-match-svn.x86_64
"

keep-only-this-text
no-match_4.1.i686
keep-this-text_64
match_2.1.x86_64

Expected Outcome

The Code Generator should produce output which does not remove non-matching lines, or at least adds a note on how the end user can include/omit that ;d to display/suppress those lines as needed:

$ sed -E 's/-[0-9][0-9]*(\.[0-9][0-9-]*|\.[a-z0-9][a-z0-9]*)*//gm;t' <<< "no-match
keep-only-this-text-1.1.2-7.el7.noarch
no-match-1.4.8-3.el7_4.1.i686
keep-this-text-1.4.8-3.el7.1.x86_64
match-1.4.8-3.el7_2.1.x86_64
no-match-svn.x86_64
"

no-match
keep-only-this-text
no-match_4.1.i686
keep-this-text_64
match_2.1.x86_64
no-match-svn.x86_64
firasdib commented 11 months ago

So ;d should only be used in list-mode?

OnlineCop commented 11 months ago

Possibly, but list-mode doesn't allow Code Generator to be selected.

firasdib commented 11 months ago

Right, thank you!

OnlineCop commented 11 months ago

The code generated for SED seems to be missing comments that other languages tend to include:

# This removes non-matching lines from the result; remove ';d' if you wish to preserve non-matching lines:

or similar could be added right before it.

jfernandz commented 11 months ago

šŸ‘ for @OnlineCop. That's exactly the point ... since you can see non matching lines as they are before and after the substitution ... The generated code for SED shouldn't include that ;d šŸ˜‰

firasdib commented 11 months ago

I'll fix this, thank you!