Need Regex to get "Name of Game"

Hi All,

I need regex to find Football in the string below:

Game Request | Member : Football

I need Football from the above string.

Thanks!
Anmol

Hello,
This pattern should work:
(?<= \ : )(.*)

*Please delete the space character between backslash and β€œ:” character

2 Likes

Thanks @olgu

Can you explain me how this regex work.

Thanks!
Anmol

Hi @anmolk171

You can try one more thing, you can use split string method like this

yourArray = yourString.Split(":",c)

Now the item at index 1 in the array would be the name of the game

Thanks,
Prankur

4 Likes

(?<= \ : ) - Is a positive lookbehind, it searches for the ": ", colon needs to be preceded by the backslash, because it’s special character.
(.*) - Is matching everything after previous pattern.

Please try the online regex testers to understand regex more.

Regards

3 Likes

That is a great solution, you can try this also :slight_smile:

yourString.Substring(yourSTring.LastIndexOf(":")+1).ToString 

Thanks,
Prankur

5 Likes

Thanks @PrankurJoshi, @olgu

Both the solutions are working for me. I want to do it with regex just for learning.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.