Support » Plugin: Search Regex » Super-helpful plugin, seems one small bug

  • Love this plugin – it makes so many changes so easy, as long as you’re very careful before hitting “Replace & Save” first!

    I’ve started using multi-line and dot-all (mentioned under Search Options here) and it looks like that functionality is a little buggy…

    For example, make sure Regex, multi-line, and dot-all are checked, and search for:

    /(src\s*=\s*['"](.+?)['"])(.*)/

    and replace with (but don’t save!):

    $1 new-attr=”1″$2

    This would add a new attribute to only the first images in all your WP posts… But you’ll see that the IMG tag’s URL unexpectedly reappears in $2!

    Because the \2 backreference is not correct, the operation is nonfunctional.

    Has anyone else run across this type of thing?

    • This topic was modified 11 months, 4 weeks ago by roam92.
    • This topic was modified 11 months, 4 weeks ago by Steve Stern.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @roam92,

    Your regex has 3 capture groups, being $2 within $1:

    $1 = from src to closing " (includes $2)
    $2 = the URL
    $3 = the remaining of the multi-line

    In a test website, it did work when the replacement string was changed to:

    $1 new-attr="1"$3

    Thanks, good catch!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Super-helpful plugin, seems one small bug’ is closed to new replies.