0

I am using WordPress and the Search Regex plugin.

I need to covert several hundred Posts that contain a script which contains a unique Photo album number.

Each script needs to be changed to a shortcode which contains the same Photo album number.

Here is an example:

Search for the script:

<tt>%%wppa%%</tt> <tt>%%album=15%%</tt>

and replace it with the shortcode:

[wppa type="album" album="15"][/wppa]

What would I place in the Search field?

and

What would I place in the Replace field?

Laurel
  • 5,965
  • 14
  • 31
  • 57

1 Answers1

0

Use this regex:

<tt>%%([^%]+)%%</tt>\s*<tt>%%([^%=]+)=([^%=]+)%%</tt>

and this replacement:

[$1 type="$2" $2="$3"][/$1]

The $ numbers in the replacement refer to the capture groups: (). Overall, it's very simple, with [^%]+ matching "not %", \s* matching whitespace, and [^%=]+ matching "not % or =".

The plugin uses PCRE, but I'm not sure if the regex needs any adjustments since I don't use the plugin. (It may require escaping the / characters.)

Laurel
  • 5,965
  • 14
  • 31
  • 57