Hello, please help with the code. Purpose: to find the text on the template on the site, for example "xxxxx-xxxx-xxxx-xxxx.

For example: There is a blog on the site and there is "xxxxx-xxxx-xxxx-xxxx" among it. And it is necessary to find among all this exactly "xxxxx-xxxx-xxxx-xxxx".

In "x" can be both a digit and a letter. The numbers can be big and small. For example: "5ghJ7-hgFJ-748b-NKLO"

  • What have you tried, have some sketches? - Anton Komyshan
  • Hint to the author: "regulars! Use regular expressions!" :) - gil9red
  • Anton Komyshan, I have not tried anything yet. I have no idea how to implement. - Spreeng

2 answers 2

Regular Expression: [a-zA-z0-9]{5}-[a-zA-z0-9]{4}-[a-zA-z0-9]{4}-[a-zA-z0-9]{4}

 $reg = "[a-zA-z0-9]{5}-[a-zA-z0-9]{4}-[a-zA-z0-9]{4}-[a-zA-z0-9]{4}"; string matchString = Regex.Match(stringToSearch, $reg).Groups[1].Value; 
  • Thanks a lot, helped :) - Spreeng

This pattern looks prettier.

 [a-zA-Z0-9]{5}(-[a-zA-Z0-9]{4}){3} 

You can protest here

  • Thank. This, too, will test) - Spreeng
  • @Spreeng By the way, that pattern is incorrect. You can insert the characters [] ^ _ `. You can test here regex101.com/r/11L1YX/1 - MihailPw