Unexpected regex behavior, dash in character class
See original GitHub issuevar token = /^[a-zA-Z0-9_!#$%&'*+.^`|~-]+$/;
console.log( token.test('Content-Type') );
The above prints false while it should be true
tested with duktape v 1.4 & nodejs v6.9.5 and latest chrome / firefox all give true
it seems that removing end regex match will fix this
var token = /^[a-zA-Z0-9_!#$%&'*+.^`|~-]+/;
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How do you escape a hyphen as character range in a POSIX ...
1. hyphen located at the middle of character class would act as a range operator. · 3. @AvinashRaj I don't think this is...
Read more >unexpected behavior in RegularExpressionProtection...
Hi Apigee Experts I am trying to put regular expression on request json ... You have a negative lookahead assertion with a character...
Read more >Character classes - JavaScript - MDN Web Docs - Mozilla
A character class. Matches any one of the enclosed characters. You can specify a range of characters by using a hyphen, but if...
Read more >Character Ranges & Class Negation in Regular Expressions
Now is an appropriate time to review the fourth character that must be escaped in a character class: The 'dash', or 'hyphen' character....
Read more >Insufficient information on hyphen behaviour inside character ...
the dash ( - ) is mostly a normal character in Regex except when used in character classes. If the dash is not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Ok, #1570 has a bug test case and a fix. I’ll merge it once the tests pass.
Hehe, thanks 😃 This one was luckily a small bug probably introduced when reworking some lexer stuff for 2.0 release.
Thanks for reporting it, now it’s covered by testcases too 😃