language: C# (mono-2.8)
date: 414 days 7 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
using System.Text;
using System.Text.RegularExpressions;
 
// code for http://kobikobi.wordpress.com/2011/01/04/net-regular-expressions-finding-acronyms-and-reversing-the-stack/
 
public class Test
{
        public static void Main()
        {
                string findAcronyms = @"
\b((?<Acronym>\w)\w*\W+)+
(?<=(?<-Acronym>.(?=.*?(?<Reverse>\k<Acronym>)))+)(?(Acronym)(?!))
\((?<-Reverse>\k<Reverse>)+\)
(?(Reverse)(?!))";
                string input = Console.ReadLine();
                MatchCollection matches = Regex.Matches(input, findAcronyms,
                        RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
                foreach (Match match in matches)
                {
                     Console.WriteLine(match.Value);
                }
        }
}