Skip to content
This repository was archived by the owner on May 14, 2020. It is now read-only.
This repository was archived by the owner on May 14, 2020. It is now read-only.

Regex: Only escape characters when necessary #1130

@michaelgranzow-avi

Description

@michaelgranzow-avi

The following rules

942432 942430 942431 942421 942420

seem to escape all characters inside the character class as a matter of course. Most of the backslashes are not needed and are indeed prone to cause problems. Inside character classes, only the caret ^, the hyphen -, the closing bracket ] and the backslash itself are metacharacters. We should heed the advice in http://www.regexguru.com/2008/04/escape-characters-only-when-necessary/, so the regex should be (double quote escaped because it's inside a string, ^ not escaped because it's not at the start of the range):

"((?:[~!@#$%^&*()\-+={}[\]|:;\"'´’‘`<>][^~!@#$%^&*()\-+={}[\]\|:;\"'´’‘`<>]*?){N})"

with N = 2, 3, 6, 8 or 12, depending on the rule.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions