RegexFunctions.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Text.RegularExpressions;
  2. public static class RegexFunctions
  3. {
  4. public static Regex ChatItemLinks = new Regex(@"<(.*?/.*?)>");
  5. public enum RegexMatchEvalType
  6. {
  7. ChatLinkName
  8. }
  9. private static string RegexReplace(string text, Regex regex, MatchEvaluator ev)
  10. {
  11. try
  12. {
  13. return regex.Replace(text, ev);
  14. }
  15. catch
  16. {
  17. return text;
  18. }
  19. }
  20. public static string SeperateCamelCase(this string value)
  21. {
  22. return Regex.Replace(value, "((?<=[a-z])[A-Z]|[A-Z](?=[a-z]))", " $1").Trim();
  23. }
  24. private static MatchEvaluator GetMatchEv(RegexMatchEvalType type)
  25. {
  26. switch (type)
  27. {
  28. case RegexMatchEvalType.ChatLinkName:
  29. return m => m.Groups[1].Captures[0].Value.Split('/')[0];
  30. default:
  31. return null;
  32. }
  33. }
  34. public static string CleanChatString(string text)
  35. {
  36. return RegexReplace(text, ChatItemLinks, GetMatchEv(RegexMatchEvalType.ChatLinkName));
  37. }
  38. }