Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Hyphen-Minus should not be escaped #39

Open
tyge68 opened this issue Apr 22, 2024 · 1 comment
Open

Simple Hyphen-Minus should not be escaped #39

tyge68 opened this issue Apr 22, 2024 · 1 comment

Comments

@tyge68
Copy link

tyge68 commented Apr 22, 2024

Currently if you escape a string with Hyphen-Minus in it it get converted to some \x2d which is then not working once executing the regexp search (for example with postgresql regexp_replace(....) which accept regexp.

I am not sure if that is an issue in postgresql or in this library, still to me it doesn't seem like minus would actually need to be escaped.
Example:

escapeRegExp('some-value-to-escape')

it returns 'some\x2dvalue\x2dto\x2descape' which is not really required for regexp I think, but maybe I am wrong.
In any cases I couldn't then use this library for my usecase.

@charmander
Copy link
Contributor

charmander commented Apr 23, 2024

\x2d should work fine in PostgreSQL’s regexp_replace. How are you using it?

SELECT regexp_replace('foo-bar-baz', '\x2d', '_', 'g');
regexp_replace
foo_bar_baz

Hyphens need escaping in general when used in character classes ([chars]).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants