webidl icon indicating copy to clipboard operation
webidl copied to clipboard

Decimal regular expression has “dead code” (so to speak)

Open bathos opened this issue 2 years ago • 1 comments

In /-?(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][+-]?[0-9]+)?|[0-9]+[Ee][+-]?[0-9]+)/er, wait, I think this will be a little easier to see if we translate to an idiomatic ES pattern first. In

/-?((\d+\.\d*|\d*\.\d+)(E[+-]?\d+)?|\d+E[+-]?\d+)/i

the second \d* can only ever match the empty string (\d{0,0}) because \d+\.\d* (\d{1,∞}\.\d{0,∞}) is inclusive of \d+\.\d+ (\d{1,∞}\.\d{1,∞}). As it “does nothing”, it seems clearer to not include it:

/-?((\d+\.\d*|\.\d+)(E[+-]?\d+)?|\d+E[+-]?\d+)/i

bathos avatar Oct 14 '22 14:10 bathos

We should change these to be JS regular expressions at the same time. No need for a Perl 5 dependency.

annevk avatar Jan 02 '23 16:01 annevk