![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Regular expression to grab unknown value I have a string of data coming from a device. I have to pull the data out of the string that I need to put into an object. this is an example of my return string: each property in my object matches a return value(ie there is a property called ecgSt1) so I really need to know how to pull out the value between the = and the ; ecgSt1=-65;ecgSt2=+65;ecgSt3=-45;p1=21,45,54;p2=45,55,21;t1=99;hr=45;hrSource=;nibp=;nibpElapsedTime=;resp=;respSource=;co2=;spo2=;o2=;agent=;agentType=;n2o= x.ecgst1=regex.Something(pattern,string)etc... this should pull the value between the = and the ; I have searched pretty thouroughly on the web, but I cant seem to get the right search terms going. Eric |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Regular expression to grab unknown value I think i found the answer ecgSt1=\s*([^;\s]*) "Eric Cathell" <depictureboy@xxxxxx> wrote in message news:%23khFwIoRJHA.3880@xxxxxx Quote: >I have a string of data coming from a device. I have to pull the data out >of the string that I need to put into an object. > > this is an example of my return string: > > each property in my object matches a return value(ie there is a property > called ecgSt1) > > so I really need to know how to pull out the value between the = and the ; > > ecgSt1=-65;ecgSt2=+65;ecgSt3=-45;p1=21,45,54;p2=45,55,21;t1=99;hr=45;hrSource=;nibp=;nibpElapsedTime=;resp=;respSource=;co2=;spo2=;o2=;agent=;agentType=;n2o= > > > x.ecgst1=regex.Something(pattern,string)etc... this should pull the value > between the = and the ; > > > I have searched pretty thouroughly on the web, but I cant seem to get the > right search terms going. > > Eric > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Regular expression to grab unknown value using the following regex you'd get a MatchCollection with app possible key/value pairs which can be added to a SDictionary quite easily. You'd be on your own from there: (?<key>[^=]+)=(?<value>[^;]+); regex rx = new Regex("(?<key>[^=]+)=(?<value>[^;]+);", RegexOption.None); Dictionary<string, string> result = new Dictionary<string, string>(); Match m = rx.Match(yourString); while (m.success) { result.add=(m.Groups["key"].Value, m.Groups["value"].Value); } //Result now has all keys and values in an easily accessible collection. Alternatively you could use: (? ?<key>[^=]+)=(?<value>[^;]+) *regex rx = new Regex("(? ?<key>[^=]+)=(?<value>[^;]+) *", RegexOption.None);Match m = rx.Match(yourString); if (m.success) { foreach(int i = 0; i < result.Groups["key"].Captures.Count; i++) { string key = result.Groups["key"].Captures[i]; string value = result.Groups["value"].Captures[i]; } } Jesse Hello Eric, Quote: > I think i found the answer > > ecgSt1=\s*([^;\s]*) > > "Eric Cathell" <depictureboy@xxxxxx> wrote in message > news:%23khFwIoRJHA.3880@xxxxxx > Quote: >> I have a string of data coming from a device. I have to pull the data >> out of the string that I need to put into an object. >> >> this is an example of my return string: >> >> each property in my object matches a return value(ie there is a >> property called ecgSt1) >> >> so I really need to know how to pull out the value between the = and >> the ; >> >> ecgSt1=-65;ecgSt2=+65;ecgSt3=-45;p1=21,45,54;p2=45,55,21;t1=99;hr=45; >> hrSource=;nibp=;nibpElapsedTime=;resp=;respSource=;co2=;spo2=;o2=;age >> nt=;agentType=;n2o= >> >> x.ecgst1=regex.Something(pattern,string)etc... this should pull the >> value between the = and the ; >> >> I have searched pretty thouroughly on the web, but I cant seem to get >> the right search terms going. >> >> Eric >> Jesse Houwing jesse.houwing at sogeti.nl |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Regular Expression help C# | .NET General | |||
| Regular Expression for ../ | .NET General | |||
| Help with a regular expression | VB Script | |||
| regular expression help | VB Script | |||
| Simple Regular Expression | PowerShell | |||