-4

I am trying to understand the following regular expression pattern:

[-\w!$%^&*()_+-|~=`{}\[\]:";'<>?,.\/]+$

\w - matches any single letter, number, or underscore.

! - negative lookahead assertion. x(?!y): matches “x” only if “x” is not followed by “y”.

$ - matches the end of input. /t$/ does not match the “t” in “eater”, but does match it in “eat”.

% - not certain

^ - tells the computer that the match must occur in the beginning of the string.

This is what I understand thus far, but can someone please explain the entire pattern? Thank you.

deniz
  • 1
  • 2
  • 2
    See https://regex101.com/r/d7ZiXA/1 – Wiktor Stribiżew May 27 '22 at 17:52
  • 1
    `! - negative lookahead assertion` no, single `!` doesn't have special meaning. Negative lookahead is entire `(?! ... )`, not single `!`. Anyway inside character class `[...]` most special characters are no longer special. More info: https://www.regular-expressions.info/charclass.html#special – Pshemo May 27 '22 at 18:00
  • 2
    This is one huge character class and a quantifier at the end, nothing else. There's no magic happening here. – f1sh May 27 '22 at 18:00
  • 1
    `+-|` is probably a mistake and probably will not do what was intended. – VGR May 27 '22 at 18:35
  • 1
    @f1sh While the `-` at the start of the character class is not a special character, I’m pretty sure it does not prevent all other hyphens in the same character class from being interpreted as ranges. `[-a-z]` would still match any lowercase ASCII letter. – VGR May 27 '22 at 23:55

0 Answers0