Skip to content

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

@bathos

Description

@bathos

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions