tags:

views:

48

answers:

1

I need to extract a set of characters in of a string. I plan on usng the RegEx.Match method (c#) but I am unclear about the RegEx pattern to use. I want to extract a pattern where it starts with // and ends with ...

Then length needs to be variable inside the matched string but the start and end characters will always be the same. In DOS, I would have done something like the following:

//*...

but I know this is not the correct syntax for RegEx.

+2  A: 

Try with pattern

"//.*?\.\.\."

or

"//.*?\.{3}"

Some codes

string data = @"some codes //to double check...
another codes //done...
//to do...";

MatchCollection matches = Regex.Matches(data, @"//(.*?)\.\.\.");
foreach (Match m in matches) {
    print(m.Groups[1].Value);
}

results

to double check
done
to do
S.Mark
those will still match "abc//test...test" tho
David Hedlund
hey wait, that's what he wants, isn't it? nevermind me, then
David Hedlund
Thanks for reminding, I am not so sure about that.
S.Mark