Regex To Match Any Characters Between Two Square Brackets

A regular expression To match any characters between two square brackets (without the brackets themselves.).

/(?<=\[)(.*?)(?=\])/

Matches:

  • [regex]
  • [pattern]
  • [com]

Non-matches:

  • regex
  • (pattern)
  • ‘pattern’

Or include the brackets…

/\[(.*?)\]/

Matches:

  • [regex]
  • [pattern]
  • [com]

Non-matches:

  • regex
  • (pattern)
  • ‘pattern’

See Also: