Do I need to escape dash character in regex? [duplicate]

You only need to escape the dash character if it could otherwise be interpreted as a range indicator (which can be the case inside a character class).

/-/        # matches "-"
/[a-z]/    # matches any letter in the range between ASCII a and ASCII z
/[a\-z]/   # matches "a", "-" or "z"
/[a-]/     # matches "a" or "-"
/[-z]/     # matches "-" or "z"

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)