Home > Back-end >  Regex match all words enclosed by parentheses and separated by a pipe
Regex match all words enclosed by parentheses and separated by a pipe

Time:10-22

I think an image a better than words sometimes.

enter image description here

My problem as you can see, is that It only matches two words by two. How can I match all of the words ?

My current regex (PCRE) : ([^\|\(\)\|] )\|([^\|\(\)\|] )

The goal : retrieve all the words in a separate groupe for each of them

CodePudding user response:

You can use an infinite length lookbehind in C# (with a lookahead):

(?<=\([^()]*)\w (?=[^()]*\))

To match any kind of strings inside parentheses, that do not consist of (, ) and |, you will need to replace \w with [^()|] :

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

See the enter image description here

  • Related