I'm not sure what you mean by "I have no idea how to implement this method." since you clear have implemented it and got exactly what I would expect from that when it runs.
So I can only assume that the example you give isn't representative of your input or what you need to replace with what. The trouble with that that while regexes are extremely powerful, compact, and very, very flexible, that al comes with a cost - they are very hard to read and understand. Indeed there are whole books just covering regular expressions and how to use them:
Mastering Regular Expressions 3e: Understand Your Data and Be More Productive[
^] for example!
We can't give you a solution unless we understand the problem - and it's probably a good idea to learn at least a bit about regexes before you even try to get someone else to write them for you as you will probably have to maintain that regex in the future and that means understanding them to a reasonable degree. If you are going to use regular expressions, you need a helper tool. Get a copy of
Expresso[
^] - it's free, and it examines and generates Regular expressions. And start with a tutorial:
Regular Expression Tutorial - Learn How to Use Regular Expressions[
^]
Good luck!