Question

I have text like the following:

Hallo ich bin Pra Lebo, | (_S ich wurde 1974 in Südafrika geboren, S_) | (_B <marker
tag="1">denn</marker> meine Eltern, | beide Angehörige der Komtoru, | sind nach dem 
Umsturz ´73 ausgewandert. B_) | Trotz meiner auswärtigen Herkunft fühle ich mich Akritiri immer
noch sehr verbunden und ich hoffe, | dass wir heute eine gute Entscheidung treffen können. | Ich 
plädiere für ein parlamentarisches Regierungssystem, | damit die Kontrolle besser gegeben ist und 
damit so schreckliche Ereignisse sich nie wieder wiederholen können. |

I would like to a regex to match strings inside (_S ... S_), another regex to match strings inside (_B ...B_) and a third one to match those spans that are not inside any of the above. Ideally, I would have three regexes. How would one go about doing this?

The first two problems are much easier and have been answered, however the third problem still remains. I need to match the largest strings not surrounded by any opening or closing round brackets. Any help is appreciated.

Was it helpful?

Solution

You can use regex (?<=\(_S)((.|\n)*?)(?=S_\)) for getting string inside (_S and S_)

Demo

Similarly you can use regex (?<=\(_B)((.|\n)*?)(?=B_\)) for getting string inside (_B and B_)

Demo2

To match these two , you can use :

(?:(?<=\(_S)((?:.|\n)*?)(?=S_\)))|(?:(?<=\(_B)((?:.|\n)*?)(?=B_\)))

Demo3

To match string that are not enclosed in brackets , you can use something like this :

(((?:^)|(?<=\)))(?:[^(])*)

Demo4

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top