开发者

Regex.Split pattern: How to split a string into repeating pattern blocks?

Let's say we have a string:

"somethinghere%C3somethinghere%83%C3%A8%C3%AF%C3%AD%C3%AEsomethinghere%C3%A7somethinghere"

What would be the Regex.Split pattern to get the following list of values:

  1. %C3
  2. %83%C3%A8%C3%AF%C3%AD%C3%AE
  3. %C3%A7

NOTE: somethinghere - can be any text that has no value and 开发者_Python百科it does not contain the '%' char;

Thanks in advance!


Looks like you need Regex.Matches instead of Regex.Split. If you want result to be list of strings you could use linq:

List<string> result = Regex.Matches(source, "(%[A-Fa-f0-9]{2})+").OfType<Match>().Select(s => s.Value).ToList();


You would probably want:

/(%[A-F0-9]{2})+/g

Assuming JavaScript-style regex syntax.

Edit:

If you want to leave the % symbol out of the match:

/(?:%([A-F0-9]{2}))+/g
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜