0

I'm wondering if someone can help me? I am struggling to write regex to match the whole of the following shortcode:

[recipe_details_sc carbs='10g carbs' time='30 mins' serves='Serves 6']

I want to select the whole shortcode.

Thank you.

1 Answers1

0

Use the square brackets as boundaries, so that you search for

start-bracket ; not-bracket (many) ; end-bracket

The only pain being that

  1. a square bracket needs to be escaped, and
  2. the square bracket is used as part of the "not character" expression ...

Both of which add up to making it difficult to read!

\[[^]]+\]

Tested using Regular Expression Test Page

Stewart
  • 17,616
  • 8
  • 52
  • 80