Skip to content

「优化」座机正则表达式存在冗余 #319

Description

@condorheroblog

原始正则:

/^(?:(?:\d{3}-)?\d{8}|^(?:\d{4}-)?\d{7,8})(?:-\d+)?$/

image

正则中的第二个定位符(^)是不必要的,可以删除,保留一个即可:

image

/^(?:(?:\d{3}-)?\d{8}|(?:\d{4}-)?\d{7,8})(?:-\d+)?$/

通过 regexp/no-useless-assertions 检查发现

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions