At the input line of the form

asdfsadfs=dfasfsdfd; sdfasdf dfsdff=sdfsdf; dsfasdfsdf=sdfsdf

How to extract what begins with the signs "=" and ";" either "=" and the end of the line (that is, from the first occurrence of the character "=" to the first occurrence of the character ";" or to the end of the line if there is no ";")?

 string x = Regex.Match(z, @"\=(.*?)[;$]").Groups[1].Value; 

The "$" character inside a character class is not perceived as the end of a line.

1 answer 1

Solution found. If the first delimiter is always there, and the latter may or may not be, then the second delimiter must be included in the character class as an excluded symbol.

 string x = Regex.Match(z, @"\=([^\=\;]+)").Groups[1].Value;