Regex To Match A Character At The Beginning And The End Of A String

A regular expression matches a character that appears at the beginning and the end of a string.

Can be useful in removing an unexpected character (” in this example) from the beginning and the end of a string.

/^\"|\"$/g

Matches:

  • regexpattern
  • regex”pattern
  • regex”pattern
  • regex”pattern

See Also:

Regex Is Copied!