Skip to content

Instantly share code, notes, and snippets.

@noahm
Last active December 25, 2015 21:59
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 noahm/7046231 to your computer and use it in GitHub Desktop.
Save noahm/7046231 to your computer and use it in GitHub Desktop.
for BOOEAN!
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
// Input string.
const string example = "Name:\r\n\r\nEmail: jasonbateman@yahoo.com\r\n\r\nPhone: 333-343-0909\r\n\r\n";
// Get a collection of matches with the Multiline option.
//MatchCollection matches = Regex.Matches(example, "^(.+)$", RegexOptions.Multiline);
MatchCollection matches = Regex.Matches(example, "^Name:([^\\n]*)$", RegexOptions.Multiline);
foreach (Match match in matches)
{
// Loop through captures.
foreach (Capture capture in match.Captures)
{
// Display them.
Console.WriteLine("--" + capture.Value);
}
}
}
}
@cyranix
Copy link

cyranix commented Oct 18, 2013

I don't have a C# environment in front of me -- is the intended result that there are no captures?

@cyranix
Copy link

cyranix commented Oct 18, 2013

Seems like your capturing group should be something like (\S[^\r\n]*$) -- ensure that there's a non-whitespace character, and then continue to match characters that aren't the known terminators.

@noahm
Copy link
Author

noahm commented Oct 18, 2013

Updated to something that works, but will capture the leading whitespace in front of a name. Should be stripped out later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment