문제

I cant find regex expression of <#anystring#>?

Ex: <#sda#> or <#32dwdwwd#> or any of string between <# and #>

I tried "<#[^<#]+#>" but this has outputted only the first occurrence.

        string sample = "\n\n<#sample01#> jus some words <#sample02#> <#sample03#> just some words ";
        Match match = Regex.Match(sample, "<#[^<#]+#>");
        if (match.Success)
        {
            foreach (Capture capture in match.Captures)
            {
                Console.WriteLine(capture.Value);
            }
        }
도움이 되었습니까?

해결책

You are using the match() method. Try reading the documentation and you will see, that it returns only the first match.

Try the matches() method instead, it returns a MatchCollection.

It would look something like this (careful, not tested written directly here)

string sample = "\n\n<#sample01#> jus some words <#sample02#> <#sample03#> just some words ";
    MatchCollection mc = Regex.Matches(sample, "<#(.*?)#>");
    foreach (Match m in mc)
        {
            Console.WriteLine(m.Groups[0]);
        }
    }

다른 팁

try this one , it should work

UPDATED

<#(.*?)#>

  • The dot is any character except new line (\n).
  • The * means 0 or more.
  • The ? is used to make it ungreedy.

source here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top