Tomasz Piotrowski
Tomasz Piotrowski

Reputation: 1

how to match nested regex

I'm trying to match WikiMedia files markups which I meet in following situation:

[[ref1]] text [[Datei:Panorama2München.JPG der [[Frauenkirche (München)|Frauenkirche]] aus in Blickrichtung Südosten]] text [[ref2]]. 

I Want to match

[[Datei:Panorama2München.JPG der [[Frauenkirche (München)|Frauenkirche]] aus in Blickrichtung Südosten]]

Upvotes: 0

Views: 116

Answers (1)

Ramzi Khahil
Ramzi Khahil

Reputation: 5052

It depends on what parts are constant? does all the strings you want to match start with "[[Datie" and have the exact amount on brackets? If so you can try this [[Datei.*[[.*]].*]]. And if its the one after "text" the try text [[.*[[.*]].*]].
But be aware that if you don't know the number of brackets then it can be tricky, but you need some assumption about them, because it's impossible to make a regular expression that matches an unknown amount of brackets. (For that you will need a stack - managed by you.)

Upvotes: 1

Related Questions