HotTeaLover
HotTeaLover

Reputation: 93

Matching the value between colon and semicolon

I have a simple question: my long text is full of: text:value;text:value;.... My question is how do you get all values between : and ;

My half-correct(?) pattern is: text:(.*);.text:

Could someone show me a better way?

Upvotes: 3

Views: 529

Answers (2)

User 12345678
User 12345678

Reputation: 7804

Pattern: \w+:(?<value>\w+);

Regex pattern = new Regex(@"\w+:(?<value>\w+);");

foreach (Match match in pattern.Matches("text:bar;text:foo;"))
    Console.WriteLine(match.Groups["value"].Value);

Prints:

bar
foo

Upvotes: 2

Rudolf
Rudolf

Reputation: 1886

This is the regex you are searching:

text:([^;]*);

Where [^;] matches everything but the semicolon.

Upvotes: 4

Related Questions