Skip to content

Instantly share code, notes, and snippets.

@Porges
Last active January 15, 2017 23:58
Show Gist options
  • Select an option

  • Save Porges/9ba3b7f94f2c14e20feb16c984406e5a to your computer and use it in GitHub Desktop.

Select an option

Save Porges/9ba3b7f94f2c14e20feb16c984406e5a to your computer and use it in GitHub Desktop.
var input = "Example task section 1 section tomorrow section tagone tagtwo tagthree tagfour";
// regex altered slightly from question
var r = new Regex(@"^([\w ]+) section (\d) section (\w+) section(?: (\w+))+$");
var g = r.Match(input).Groups;
var output = $"{g[1]} !{g[2]} ^{g[3]} " +
string.Join(" ", g[4].Captures.Cast<Capture>().Select(x => "#" + x));
// output: "Example task !1 ^tomorrow #tagone #tagtwo #tagthree #tagfour"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment