What's the magic there?
Hi, guy!
In the comments below, the numbers refer to the table rows in post #2 and spaces are replaced by "_" for legibility purposes.
A keyword is a non-null sequence of characters different from "
;", thus a keyword = "
[^;]+".
3. "
([^;]+);_"
Between round brackets: the keyword that will be repeated, followed by "
;_".
5. "
\2"
The repeated keyword (captured group nr. 2).
1. + 2.
The keyword to look for is possibly preceded by 0, 1 or more other keywords with semi-colons in between, thus 2 possible variants: "
([^;]+;_)*" or "
(.*;_)?".
6. + 7.
The 2nd occurrence of the keyword is possibly followed by 0, 1 or more other keywords with semi-colons in between, thus 2 possible variants: "
(;_[^;]+)*" or "
(;_.*)?". Note that the semi-colon starts the RegEx part this time.
4.
Between the keyword and its repetition, you can have 0, 1 or more other keywords, with semi-colons in between.
I made the RegEx as general as possible, so as to normally cover all the cases.
Moreover, it is important to use the semi-colon at each transition: between 2 and 3, 3 and 4, etc. By doing so, you know that no RegEx part matches a substring of a keyword.
I could have used non-capturing groups in 2., 4. and 6 but it would have been even more illegible.