Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Regular expression to grab unknown value

Reply
 
Old 11-14-2008   #1 (permalink)
Eric Cathell


 
 

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 SpecsSystem Spec
Old 11-14-2008   #2 (permalink)
Eric Cathell


 
 

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 SpecsSystem Spec
Old 11-16-2008   #3 (permalink)
Jesse Houwing


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46