I have this string "Date.2014.07.04"
Then if I want to get "07" from string above using regex.
How do I do that?
I don't want to use split.
Why I don't want to use split? Because when we split, the result will be in array of string. And usually we'll try to get the index of array that we want. In my case it will be
var date = "Date.2014.07.04";
date.Split('.')[2];
But let say we update the date to new string (Remove all '.').
var date = "Date20140704";
date.Split('.')[2];
This will throw an error because it can't find index number 2.
By using regex, this error won't occur and it will just return empty string if the pattern that we want can't be found inside string. :)