I’ve a string like this,
-p User/Dob -f MM/dd/yyyy -flag somevalue
How can I extract values like below using Regex,
p = "User/Dob"
f = "MM/dd/yyyy"
flag = somevalue
This is what I’ve tried so far,
public static string MERGE_ARGS_REGEX = @"-[a-z]";
var arguments = Regex.Matches(metadata, MERGE_ARGS_REGEX)
.Select(x => x.Value.Replace("\", ""))
.ToList();
var argumentValues = Regex.Split(metadata, MERGE_ARGS_REGEX)
.Where(x => !string.IsNullOrEmpty(x))
.Select(x => x.Trim())
.ToList();
I’m getting the values array in the argument argumentValues
. I think the code can be improved. Can you someone please advise how to do it better.