开发者

RegEx to extract characters in a string

开发者 https://www.devze.com 2022-12-15 06:33 出处:网络
I need to extract a set of characters in of a string.I plan on usn开发者_StackOverflow社区g the RegEx.Match method (c#) but I am unclear about the RegEx pattern to use.I want to extract a pattern wher

I need to extract a set of characters in of a string. I plan on usn开发者_StackOverflow社区g 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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消