I wanted to extract the date pattern "mm/dd/yyyy" from a string, for example, given the string:
"The quick brown fox on 4/26/2018 decided to jump over the moon"
I wanted to extract this date pattern from any string in C#. In starting out I used:
https://regex101.com/r/yG2zN1/1
Using the pcre (PHP) flavor I came up with the following and it seemed to work well for this date format in any sentence:
\d{1,2}\/\d{1,2}\/\d{4}\b
However when I put this in my C# code it would not work:
Regex rx = new Regex(@"\d{1,2}\/\d{1,2}\/\d{4}\b");
MatchCollection mc = rx.Matches(myTestString); //get mm/dd/yyyy
string date = mc[0].Value;
mc comes out false? No match?
So I went over to a couple Dot NET Regex test sites and tried http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx
\d{1,2}\/\d{1,2}\/\d{4}\b - it fails on those sites also for my test string above.
My question is why does "\d{1,2}\/\d{1,2}\/\d{4}\b" work on the PHP regex to extract the date of format mm/dd/yyyy from any string but it does not work with C# regex as shown above?