c# - Regular expression to extract a specific string from a given string -
i having string like: "abc xyz: id# 1000123, test, test 1, test 1234, "
i need write regular expression extract id 1000123
.
i have tried thing like:
regex betweenofregexcompiled = new regex("id# (.*), ", regexoptions.compiled);
but gives "1000123, test, test 1, test 1234".
so, how specify first occurrence of ", "
?
gets number (i.e. chars to, not including, first comma) ...
"id# ([^,]*),"
if want make numbers explicity then...
"id# ([0-9]*),"
for non-regex version ...
string text = "abc xyz: id# 1000123, test, test 1, test 1234, "; string num = text.split(new char[] {','})[0].split(new char[] {' '})[3];
Comments
Post a Comment