Regex replace using a repetitive capture

Posted by Zac on Stack Overflow See other posts from Stack Overflow or by Zac
Published on 2010-05-21T16:41:57Z Indexed on 2010/05/21 17:20 UTC
Read the original article Hit count: 204

Filed under:
|

I have a table like:

A | 1  
A | 2  
B | 1  
B | 2  
B | 3

I'm trying to transform it to look like this:

A { 1 | 2 }  
B { 1 | 2 | 3 }

I've come up with this which will match correctly I just can't figure out how to get the repeated capture out.

(A|B)|(\d)(\r\n\1|(\d))*

© Stack Overflow or respective owner

Related posts about regex

Related posts about capture