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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -