regular expression problem
-
Hi The pattern is sth like this:
^-?((?<X>[0-9]{0,8})/(?<Y>[0-9]{0,15})|(?<X>[0-9]{0,8}))\*?$
and I want to have the variables in their named groups as following X=... Y=... I don't know how to use MatchCollection, CaptureCollection ,etc. Can anyone help me? :confused: -
Hi The pattern is sth like this:
^-?((?<X>[0-9]{0,8})/(?<Y>[0-9]{0,15})|(?<X>[0-9]{0,8}))\*?$
and I want to have the variables in their named groups as following X=... Y=... I don't know how to use MatchCollection, CaptureCollection ,etc. Can anyone help me? :confused:A good starting point would be MSDN help ;) That section is extensive and pretty well written. Let's start with a simpler pattern. Once you get it working you can make it more complex. Suppose your pattern is smth like the following:
(?<var1>\w+)
"var1" is the name of your captureRegex r = new Regex(patter<, RegexOptions> );
MatchCollection mc = r.Matches(your_text_to_match);
if (mc.Count > 0)
{
// iterate though the collection
// get the value with: mc[i].Groups["var1"].Value;
}Well, something along these lines anyway, I'm typing it from the memory, can't check the syntax on the home pc.
-
A good starting point would be MSDN help ;) That section is extensive and pretty well written. Let's start with a simpler pattern. Once you get it working you can make it more complex. Suppose your pattern is smth like the following:
(?<var1>\w+)
"var1" is the name of your captureRegex r = new Regex(patter<, RegexOptions> );
MatchCollection mc = r.Matches(your_text_to_match);
if (mc.Count > 0)
{
// iterate though the collection
// get the value with: mc[i].Groups["var1"].Value;
}Well, something along these lines anyway, I'm typing it from the memory, can't check the syntax on the home pc.
-
Hi The pattern is sth like this:
^-?((?<X>[0-9]{0,8})/(?<Y>[0-9]{0,15})|(?<X>[0-9]{0,8}))\*?$
and I want to have the variables in their named groups as following X=... Y=... I don't know how to use MatchCollection, CaptureCollection ,etc. Can anyone help me? :confused:another site that has helped me a lot in the past is http://www.regular-expression.info/[^] they even have a tool that you can use to quickly test your regex's
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.