noxone / regex-generator

Generate regular expressions from sample texts.
https://regex-generator.olafneumann.org
MIT License
398 stars 66 forks source link

Pattern starting with hyphen throws error in grep #506

Closed IoLimmer closed 4 months ago

IoLimmer commented 4 months ago

With grep, when you pass a pattern that starts with a hyphen, grep will misinterpret this as an option flag and throw an error. This doesn't seem to be accounted for on the site.

grep -P -i "-[A-Za-z0-9]+" test.txt

Seen here

When passed on the terminal with lscpu I get this error:

grep: invalid option -- '['
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.

Admittedly this can be fixed easily by adding a backslash infront of the hyphen but I thought it was worth mentioning.

noxone commented 4 months ago

Hi @IoLimmer , thank you for filing this. I can reproduce the issue and will add a fix for that.