Created
January 4, 2011 21:11
-
-
Save kobi/765417 to your computer and use it in GitHub Desktop.
.Net Regular Expressions - Finding Acronyms, and Reversing the Stack - Sample Program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = @"Hello World (hw) and maybe Home work (HW), | |
And this: Are We Going To Have To Go Through ALL This Again? (AWGTHTGTATA), | |
but not this (tn), a b c (Abc) d e f (ef) g (g) , yooo (o), | |
From beneath you, it devours (fbyid)"; | |
MatchCollection matches = Regex.Matches(input, findAcronyms, | |
RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase); | |
foreach (Match match in matches) | |
{ | |
Console.WriteLine(match.Value); | |
} | |
Console.ReadKey(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello World (hw) | |
Home work (HW) | |
Are We Going To Have To Go Through ALL This Again? (AWGTHTGTATA) | |
a b c (Abc) | |
e f (ef) | |
g (g) | |
From beneath you, it devours (fbyid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment