Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 0.61 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to use RegEx regarding second instance and negation
  2. string[] inputs =
  3. {
  4.     "<link href="6e18f2dc-1d66-4e7e-b6e7-4a68a4217feb#SectionId">",
  5.     "<link href="6e18f2dc-1d66-4e7e-b6e7-4a68a4217feb">"
  6. };
  7.  
  8. string pattern = @"(?<=<links+href="")[^#]+(#.+?)(?="">)";
  9.  
  10. foreach (var input in inputs)
  11. {
  12.     Console.WriteLine("Input: " + input);
  13.     string result = Regex.Replace(input, pattern, "$1", RegexOptions.IgnoreCase);
  14.     Console.WriteLine("Result: " + result);
  15. }
  16.        
  17. string guidPattern = @"[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}";
  18. string pattern = @"(?<=<links+href="")" + guidPattern + @"(#.+?)(?="">)";