Skip to content

Instantly share code, notes, and snippets.

@JohanLarsson
Created October 16, 2014 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohanLarsson/c295f32f4e3e6b7eb355 to your computer and use it in GitHub Desktop.
Save JohanLarsson/c295f32f4e3e6b7eb355 to your computer and use it in GitHub Desktop.
var symbols = UnitBase.AllUnitsStatic.Select(x => x.Symbol).ToArray();
var symbolsPattern = string.Join("|", new[] { "1" }.Concat(symbols));
var pattern = string.Format(@"(?<Unit>
(?<Symbol>({0}))
(
(?:\^)
(?<Power>[+-]?\d+)
)?
|
(?<Op>[⋅\*\/])
)", symbolsPattern);
var matches = Regex.Matches(s, pattern, RegexOptions.IgnorePatternWhitespace);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment