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:
- %C3
- %83%C3%A8%C3%AF%C3%AD%C3%AE
- %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
精彩评论