I take a string of the form xxxx: xxxxx@xxx.xx.xxx.xx: xxx from the StreamReader file. I need to parse the line into 4 parts (before ":", before "@", after "@", and after the second ":" ) and assign values ​​to 4 variables. The question is, what will the regular expression look like for this task?

  • And the problem is what? - Pavel Mayorov
  • one
    Answer строка.Split(":@".ToCharArray()); array elements somehow assign to 4 variables. If it’s very boring, the regular season will look like this [:@] :) - nick_n_a
  • Regular made string pattern = @ "(. *): (. *) @ (. *): (. *)"; - cruim
  • If possible, publish the solution found in response to your question . I am sure it will help many of your colleagues in the future. - Nicolas Chabanovsky

1 answer 1

Did like this

  public static void ParsingProxy() { var xx = new StreamReader("proxy.txt"); string input = xx.ReadLine(); string pattern = @"(.*):(.*)@(.*):(.*)"; Regex regex = new Regex(pattern); Match match = regex.Match(input); proxyLogin = match.Groups[1].Value; proxyPass = match.Groups[2].Value; proxy = match.Groups[3].Value; port = match.Groups[4].Value; //xx.Close(); }