Click here to Skip to main content
15,669,294 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi there,
I'm new to regular expression and I'm trying to learn it.
I have a string like this:
#EXTINF:-1, tvg-name="THE NAME" tvg-logo="THE LOGO" group-title="THE TITLE",THE ITEM

I'm going to check if THE TITLE part is matched textBox1.Text

What I have tried:

I know that I should change ""([^""]+)"" part in group-title=, But whatever I do it does not work.
How can I set the pattern string to do so?

string pattern = @"\btvg-name=""([^""]+)"".tvg-logo=""([^""]+)"".group-title=""([^""]+)"",(.*?)\n*(https?\S+)";

if (Regex.IsMatch(myString, pattern)){
//Do Somthing
Updated 10-Oct-22 7:54am
PIEBALDconsult 10-Oct-22 15:07pm    
Is this different from your earlier question?

1 solution

Sorry, but your question is not clear...

Seems you want to find a substring within a title... Regex is not for such of requirements.
If you want to get a text within a "group-title=", try this: .group-title=\"(.*?)\"
Example: regex101: build, test, and debug regex[^]

For further details: Regular Expression Tutorial - Learn How to Use Regular Expressions[^]


string mystring = @"#EXTINF:-1, tvg-name='THE NAME' tvg-logo='THE LOGO' group-title='THE TITLE',THE ITEM";
string pattern = ".group-title=\'(.*?)\'";

Regex r = new Regex(pattern);
MatchCollection mc = r.Matches(mystring);
foreach(Match m in mc)
	Console.WriteLine($"{m.Index} => {m.Value}");

In case you want to use ["] instead of ['] in a string, use double ["], for ex.:
string mystring = @"#EXTINF:-1, tvg-name=""THE NAME"" tvg-logo=""THE LOGO"" group-title=""THE TITLE"",THE ITEM";

is equivalent to previous statement.
Share this answer
Jake-J 10-Oct-22 17:23pm    
Thank you. But how can I put this in the pattern string? I have some difficulties setting it as a string.
by the way, doe's this ignore all the other parts and only return the text within quotation marks of group-title="" ?
Maciej Los 11-Oct-22 6:23am    
See updated answer.
Jake-J 12-Oct-22 16:13pm    
Sorry but that does not work. It's an m3u file and it uses this format. I can't use ['] or [""] instead of ["], Also I've tried to use text.Replace to change input before matching regex, but it makes context error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900