1

Yaron Koren's ReplaceText MediaWiki extenion allows me to use regular expressions to replace text in MediaWiki. I have about 300 MediaWiki pages that have two instances of a template. I want to delete only the second template using regular expressions. (replace it with nothing)

I have:

}} <--end of first template-->

{{Template Call

|blahField=blahValue

|blahField=blahValue

|...

}}

I think I want to search for: ^[ \\}} \r \\{{ *? ]

and replace it with: ^[ \\}} ]

but this is not producing the result I want when I test it at rexv.org

Appreciate some help with regular expressions.

Toto
  • 89,455
  • 62
  • 89
  • 125
CW Dillon
  • 156
  • 1
  • 8

3 Answers3

1

On the extension page it says

The set of regular expressions allowed is basically a small subset of the PHP and MySQL regular-expression sets (it has only been tested with MySQL - whether it works on other database systems is unknown). The characters that one can use in the search string are "( ) . * + ? [ ] |"

So maybe the characters you are using don't work. Is it possible the \ is messing it up?

Adrian Archer
  • 2,323
  • 1
  • 17
  • 20
  • This was exactly the clue that I needed. Still, I think the function is touch-n-go but I guess that's up to us *users* to explain how we would like the function to behave any differently. It's great to have options! – CW Dillon Apr 18 '12 at 10:47
0

ReplaceText is not suitable for such replacements. Use PyWikipediaBot or AutoWikiBrowser.

Nemo
  • 2,441
  • 2
  • 29
  • 63
  • I ended up making these changes all by hand. Alas, we cannot use PyWikipediaBot. I had never seen AutoWikiBrowser before but I would not have been able to use it either. ReplaceText was my only option for anything automated. Still, it seems like it should have been possible. I'm convinced that the problem lies with the type of regex I was using. Is there a way of doing regex that is specific to SQL? – CW Dillon Dec 15 '12 at 22:35
0

I have some hack here:

  1. Make your {{Template Call}} Template to empty.
  2. Use ReplaceText to Replace \{\{ *Template[ _]Call (with regex to avoid badly-formatted calls) to {{subst:Template Call.
  3. Then the places you have Template Call will be replace by contents of {{Template Call}}, which is empty.

Hope it helps.

Alex Fang
  • 1
  • 1