vb.net - Getting a blank value or - + number $value to show in Regex -


msgtype=getmarketauction&symbol=xlf&auctionprice=24.50&auctionsize=57138&auctionimbalance=0&auctionimbalancemkt=0&auctionindnetchange=&closingprice=24.54&bidprice=24.36&askprice=24.37&ec=0&es=&auctionimbalancestatus=&auctionmktimbalancestatus=&delta= 

i trying pull data needed out of regex line above. using vb.net have first 5 things stuck once there -/+ $ number needed displays no character.

this works far.

dim r new system.text.regularexpressions.regex("symbol=(?<1>.\w+)\&auctionprice=(?<2>.\d.\d+)\&auctionsize=(?<3>.\d+)\&auctionimbalance=(?<4>.a*)\&auctionimbalancemkt=(?<5>.a*)") 

auctionindnetchange=(i looking here pull value from)

thanks!

you can use following regex:

symbol=(?<1>[^&]*)&auctionprice=(?<2>[^&]*)&auctionsize=(?<3>[^&]*)&auctionimbalance=(?<4>[^&]*)&auctionimbalancemkt=(?<5>[^&]*)&auctionindnetchange=(?<6>[^&]*) 

see demo

note not have use numbers in names of capture groups, can remove ?<n> , same result.

also, replaced subpatterns in capturing groups [^&]* means 0 or more characters other &, since of them inside query string.

however, can use non-regex way system.web.httputility.parsequerystring (do not forget add reference system.web!):

dim querystr string = "msgtype=getmarketauction&symbol=xlf&auctionprice=24.50&auctionsize=57138&auctionimbalance=0&auctionimbalancemkt=0&auctionindnetchange=&closingprice=24.54&bidprice=24.36&askprice=24.37&ec=0&es=&auctionimbalancestatus=&auctionmktimbalancestatus=&delta="         dim qscoll system.collections.specialized.namevaluecollection = httputility.parsequerystring(querystr)         console.writeline(string.format("auctionsize: {0}, symbol: {1}, auctionprice: {2}, auctionsize: {3}, auctionimbalance: {4}, auctionimbalancemkt: {5}, auctionindnetchange: {6}",         qscoll("auctionsize"), _         qscoll("symbol"), _         qscoll("auctionprice"), _         qscoll("auctionsize"), _         qscoll("auctionimbalance"), _         qscoll("auctionimbalancemkt"), _         qscoll("auctionindnetchange"))) 

output:

auctionsize: 57138, symbol: xlf, auctionprice: 24.50, auctionsize: 57138, auctionimbalance: 0, auctionimbalancemkt: 0, auctionindnetchange:  

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -