Pregunta

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);
            }
        }
¿Fue útil?

Solución

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]);
        }
    }

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top