RegEx Help!!

V

Vai2000

Can someone help me with expression needed to extract the entire string

FOO*1*DATA*DATA*ID~

1. This string pattern is embedded in a super long string..

TIA

This is my unsuccessful attempt
Regex re = new Regex("[F][O][O][*][0-9][*][~]");
MatchCollection m = re.Matches(content);
ArrayList al=new ArrayList();
foreach (Match m in m)
{
al.Add(m.Value);
}
 
J

Jon Shemitz

Vai2000 said:
Can someone help me with expression needed to extract the entire string

FOO*1*DATA*DATA*ID~

If you really want to just find FOO*1*DATA*DATA*ID~ in a longer
string, you can use @"FOO\*1\*DATA\*DATA\*ID~" as the Regex pattern.

Otoh, if you really want to just find the literal string,
String.IndexOf is going to be faster than a Regex.
 
H

Hans Kesting

Can someone help me with expression needed to extract the entire string
FOO*1*DATA*DATA*ID~

1. This string pattern is embedded in a super long string..

TIA

This is my unsuccessful attempt
Regex re = new Regex("[F][O][O][*][0-9][*][~]");
MatchCollection m = re.Matches(content);
ArrayList al=new ArrayList();
foreach (Match m in m)
{
al.Add(m.Value);
}

Your regex matches a string FOO*1*~ (where "1" could be any number from
0-9). It doesn't match the string you give in your example, because of
the "DATA*DATA*ID" part.

If the string you are after starts with "FOO*1*" (but any number
instead of the 1) and ends with "~", you could use:
FOO\*[0-9]\*[^~]*~

the "[^~]*" part matches any string not containing a ~
(note: instead of "[F][O][O]" you can simply use "FOO")

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top