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

Hex RegEx misses hex values #138

Open
kungfooman opened this issue Nov 28, 2021 · 0 comments
Open

Hex RegEx misses hex values #138

kungfooman opened this issue Nov 28, 2021 · 0 comments

Comments

@kungfooman
Copy link
Sponsor Contributor

There is this RegEx:

ganja.js/ganja.js

Line 1606 in 5aca551

/^\d+[.]{0,1}\d*[E][+-]{0,1}\d*|^\.\d+[E][+-]{0,1}\d*|^0x\d+|^\d+[.]{0,1}\d*|^\.\d+/g, // 3: literal hex, nonsci numbers

Broken down between | with example match for illustration:

'123.123E-123'.match(/^\d+[.]{0,1}\d*[E][+-]{0,1}\d*/g); // ✔️
'.123E-123'   .match(/^\.\d+[E][+-]{0,1}\d*/g         ); // ✔️
'0x123'       .match(/^0x\d+/g                        ); // ✔️
'0xABC'       .match(/^0x\d+/g                        ); // ❌
'123.123'     .match(/^\d+[.]{0,1}\d*/g               ); // ✔️
'.123'        .match(/^\.\d+/g                        ); // ✔️

The result is a token stream containing too many tokens:

image

I propose this RegEx, adding capital x via [xX], a-f and A-F:

'0xaAbB'.match(/^0[xX][\da-fA-F]+/g); // ✔️
'0XaAbB'.match(/^0[xX][\da-fA-F]+/g); // ✔️
'0x1234'.match(/^0[xX][\da-fA-F]+/g); // ✔️
'0X1234'.match(/^0[xX][\da-fA-F]+/g); // ✔️
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

1 participant