firasdib / Regex101

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

. (dot) in a Character class capturing all #2121

Closed isaacwein closed 11 months ago

isaacwein commented 11 months ago

Bug Description

. (dot) in a Character class capturing all

Reproduction steps

golang regex `^(https?://)?([\w.-_]+\.)?xyz\.com(?:\:\d{2,5})?$`gm match to htp://aa.xyz.com it should only match to http://aa.xyz.com

Expected Outcome

it shouldn't match but its matches it looks like the dot thinks that it should capture all but a dot in a Character class is not a wildcard if i would change the regular expiration to `^(https?://)?([\w-_.]+\.)?xyz\.com(?:\:\d{2,5})?$`gm the . to the lest in the Character class it would work as Expected

Browser

115.0.5790.110 (Official Build) (64-bit) (cohort: Stable)

OS

Microsoft Windows 11 Version 22H2 (0S Build 22621.2070)

how it is image

how it should be image

isaacwein commented 11 months ago

after all i test it in a go playground https://go.dev/play/p/Rg4s_Q4kJr5 https://go.dev/play/p/HudPpY5p4AE sorry if I didn't do it in the beginning and it actually works like that in Go if so or I missing something in regular expressions or its a bug in Go 🫢

i tried to Reproduce it like this https://go.dev/play/p/Rg4s_Q4kJr5 and it didnt have the same bug

isaacwein commented 11 months ago

i think this issue should be changed to a Question label rather then a bug

firasdib commented 11 months ago

Your problem is [\w.-_] as you have created a character range. Escape the dash \- and it should work as expected.

In the future, please take these questions either on Discord or IRC.

isaacwein commented 11 months ago

Thank you I didn't realize that a dash is a reserved character for a character class thank