WordPress Shortcode Regular Expression

A regular expression to match a WordPress shortcode, which is written inside two square brackets.

/^\[([a-z-_0-9]+)([^\[]+)*(?:\](.*)\[\/\1\]|\s+\/\])$/

Matches:

  • [wordpress][/wordpress]
  • [wordpress parameter=”value”][/wordpress]

Non-matches:

  • [wordpress]
  • [Wordpress /]