Ask your WordPress questions! Pay money and get answers fast! (more info)

REGEX to remove code from posts

  • SOLVED

I'm using [[LINK href="https://interconnectit.com/products/search-and-replace-for-wordpress-databases/"]]interconnect tool[[/LINK]] (search & replace script) to remove some code from a lot of WP posts.

I could manage to remove/change some content, but there is a shortcode + text code that I wasn't able to remove.

The code has the following pattern:

[toggle title="QUADRO DE VAGAS"]

[quadro]
some variable text...
[/quadro]

[/toggle]


Real example:

[toggle title="QUADRO DE VAGAS"]

[quadro]
CARGO;VAGAS;REQUISITOS;JORNADA;VENC. (R$);TAXA (R$)
Auxiliar de Administração;1;Ensino Fundamental Completo.;40 horas;1.014,94;100,00
Oficial Administrativo;CR;Ensino Médio Completo.;40 horas;2.074,01;120,00
[/quadro]

[/toggle]


Could you build a regular expression to identify all code from [toggle title="QUADRO DE VAGAS"] to [/toggle] (including "toggle" shortcode)?

The regex should be build in a way that I can put in in the search field of the interconnect between the "/ /" (attached image).

Thanks!

Answers (3)

2017-01-15

Rempty answers:

Hello
You can use this regex
\[toggle title="QUADRO DE VAGAS"]((.+?)?\[\/toggle\])?
and check mark the s(try without checkmark too)
Apply first in a test enviorement or make a db backup


gualha comments:

Will try this. Thanks.
I can make a "dry run" for testing and also DB is backed up.

2017-01-15

Bob answers:

You want to remove shrotcode only and keep text right?

why you want to remove/replace shortcodes? are you switching theme?


gualha comments:

Hello Bob! I need to remove shortcode [toggle title="QUADRO DE VAGAS"] including all text between shortcode opening/closing brackets.

Still the same theme for now, but this code that I'm trying to remove isn't compatible with Google AMP pages.

2017-01-15

Reigel Gallarde answers:

you don't really need to remove this shortcode...

you can have it even when using amp pages, where it would only show on normal pages and not on amp pages..

let me know if you're interested in this kind of approach...