firasdib / Regex101

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

Why does substitution includes a string that is not part of any group #1935

Closed serranomorante closed 1 year ago

serranomorante commented 1 year ago

Bug Description

Substitution includes a string that is not part of any group in the replacement.

Issue with Regex101 substitution

Reproduction steps

Here's the public link to the regex

Expected Outcome

Instead of This string before date should not be included 01 oct. 2022 0_00 PM - 000 0000 0000.mp4, the output should be 01 oct. 2022 0_00 PM - 000 0000 0000.mp4

Browser

Edge latest

OS

Windows 10 Pro latest

DustinByfuglien commented 1 year ago

There is no bug. In source string fragment 01 oct. 2022 0_00 PM AnotherString_ 000 0000 0000 replaced with 01 oct. 2022 0_00 PM - 000 0000 0000.mp4. So source string correctly became This string before date should not be included 01 oct. 2022 0_00 PM - 000 0000 0000.mp4

serranomorante commented 1 year ago

01 oct. 2022 000 PM AnotherString 000 0000 0000

Thanks for the quick response!

What should I do to get just 01 oct. 2022 0_00 PM AnotherString_ 000 0000 0000 as the result? Or is it simply not possible?

DustinByfuglien commented 1 year ago

You can use ^.*? in the beginning of your regex ^.*?(\d{1,2}\s\w{1,5}\.\s\d{4}[^_]+_\d{1,2}\s[^\s]+)\s[^_]+_\s(.+)

serranomorante commented 1 year ago

You're right! Thanks!

firasdib commented 1 year ago

Try the ”List”-function!Vänliga hälsningar / Best regards,Firas DibOn 31 Oct 2022, at 01:04, Patricio Serrano @.***> wrote: Closed #1935 as completed.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>