-2

I'm using a regex pattern to locate a string to be deleted, which is delimited by two strings (say, "START" and "FINISH"). So it's STARTsome_string_to_deleteFINISH

Problem is that START and FINISH strings are html tags which have < > characters.

When I use online regex testers, they pattern works fine but when I insert the expression in Wordpress plugins that I use (e.g. WPEMatico that handles RSS to New Posts), I keep getting errors.

I tried escaping special characters with backslash. Doesn't work.

Any advice?

Here's an example of the string I used:

==========================================
(\<!-- Facebook Comments Plugin for WordPress).+?(<\/comments>)
==========================================
Graham
  • 3,153
  • 3
  • 16
  • 31
Matan
  • 1
  • 1

1 Answers1

1

You probably don't have "single-line mode" turned on. Single-line mode allows the . to match newlines.

For example this regular expression doesn't work because single-line mode isn't turned on. But this one does work.

If your regular expression engine supports single line mode, you might be able to enable single-line mode by preceding your regex with (?s): (?s)<!-- Facebook Comments Plugin for WordPress.+?<\/comments>. If not, then something like this should work: <!-- Facebook Comments Plugin for WordPress(?:.|[\r\n])+?<\/comments>

Note I've removed the () because they were superfluous unless you actually want to capture the text.

Graham
  • 3,153
  • 3
  • 16
  • 31