Pergunta

I have about 520 lines that look a bit like this:

**[[Amnesia]]. Parents: [[Slowpoke]] [[Slowbro]], [[Snorlax]]

**[[Charm]]. Parent: [[Cottonee]]

**[[Curse]]. Parents: [[Slowpoke]], [[Slowbro]], [[Slowking]], [[Turtwig]], [[Grotle]], [[Torterra]], [[Ferroseed]], [[Ferrothorn]]

**[[Endure]]. Parents: [[Shieldon]], [[Bastiodon]]

and I want to use F&R somehow to change every instance of [[word]] after "Parents:" (e.g. not Amnesia, Charm etc.) to {{mpic|word}}, and remove all the commas, so that a line looks like this:

**[[Amnesia]]. Parents: {{mpic|Slowpoke}} {{mpic|Slowbro}} {{mpic|Snorlax}}

I have searched and searched but really don't know if this is possible in only one or two actions (I don't mind if I have to do a few things - 10 times is better than 520 times). I only have Notepad++ version 5.9 (and cannot update) but I have Word too, so please help with either if you can!

Foi útil?

Solução

Aww egg moves! Try this regex:

(?:.*Parents?:|\G)[\s,]*\K\[\[([^\]]+)\]\],?

Replace by:

{{mpic|$1}}

regex101 demo

That should do it :)

(?:            
  .*Parents?:  # begins with ".*Parents?:"
|              # or
  \G           # at the end of previous match
)
[\s,]*         # match spaces and commas
\K             # restart the match
\[\[           # match twin open square brackets
([^\]]+)       # capture what's inside the square brackets
\]\]           # match twin close square brackets
,?             # match any comma that comes after it

I think that \G was implemented in v6x versions. Try this workaround:

\[\[([^\]]+)\]\](?![^:\n]*:),?

And replace with the same thing as before. That one is a little simpler though I guess works just as well. It matches [[ ... ]] as long as it doesn't have a : somewhere ahead on the same line.

Outras dicas

Go with following steps in Notepad++ :

Step 1: Find All '[[' & Replace All with '{{mpic|'

Step 2: Find All ']]' & Replace All with '}}'

Step 3: Find All ',' & Replace All with ''

Step 4: Find All '{{mpic|' & Replace All with '[['

(Note - For Step 4, kindly put ** in front of both strings while finding and replacing. While answering this question, if I put ** in front it becomes bold.)

Step 5: Find All '}}.' & Replace All with ']]'

Your problem will be solved.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top