Пример текст: < /p>
BlahBlahBlah\~Start capture\~Yadda\~Yadda\~Yadda\~LOOP1 hello1\~LOOP2 hello2\~LOOP3 hello3\~End stuff\~
< /code>
regex: < /p>
(?\\~Start\[^\~\]*)(?\.*?)(?\(?:\~(?:LOOP)\\d\[^\~\]*)(.*?))+(?\\~End stuff\~)
< /code>
Цель состоит в том, чтобы запустить замену, чтобы обмениваться последним циклом (Loop3) с первым. < /p>
желаемый вывод: < /p>
BlahBlahBlah\~Start capture\~Yadda\~Yadda\~Yadda\~LOOP3 hello3\~LOOP2 hello2\~LOOP1 hello1\~End stuff\~
< /code>
Заранее спасибо за любые предложения. < /p>
var Regex = new System.Text.RegularExpressions.Regex(@"(?~Start[^~]*)(?.*?)(?(?:~(?:LOOP)\d[^~]*)(.*?))+(?~End stuff~)");
var Text = "BlahBlahBlah~Start capture~Yadda~Yadda~Yadda~LOOP1 hello1~LOOP2 hello2~LOOP3 hello3~End stuff~";
// This is the wrong syntax to express the loops group capture collection.
// Note:${loops{2}} is also wrong
var Output = Regex.Replace(Text, "${firstCapture}${randomStuff}${loops(2)}${loops(1)}${loops(0)}${end}");
//BlahBlahBlah~Start capture~Yadda~Yadda~Yadda${loops(2)}${loops(1)}${loops(0)}~End stuff~
// This works, just wanting to get it in one bite if possible.
var MyMatch = Regex.Match(Text);
var Output2 = Regex.Replace(Text, $"${{firstCapture}}${{randomStuff}}{MyMatch.Groups("loops").Captures(2)}{MyMatch.Groups("loops").Captures(1)}{MyMatch.Groups("loops").Captures(0)}${{end}}");
//BlahBlahBlah~Start capture~Yadda~Yadda~Yadda~LOOP3 hello3~LOOP2 hello2~LOOP1 hello1~End stuff~
Подробнее здесь: https://stackoverflow.com/questions/796 ... e-collecti
.NET recex replyx - Как обратиться к отдельному элементу коллекции захвата в замене? ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
.NET recex replyx - Как обратиться к отдельному элементу коллекции захвата в замене?
Anonymous » » в форуме C# - 0 Ответы
- 4 Просмотры
-
Последнее сообщение Anonymous
-
-
-
.NET recex replyx - Как обратиться к отдельному элементу коллекции захвата в замене?
Anonymous » » в форуме C# - 0 Ответы
- 2 Просмотры
-
Последнее сообщение Anonymous
-
-
-
.NET recex replyx - Как обратиться к отдельному элементу коллекции захвата в замене?
Anonymous » » в форуме C# - 0 Ответы
- 2 Просмотры
-
Последнее сообщение Anonymous
-