text: Q:
  
  finding a variable from string input and extracting it with regex c#
  
  ~I have a client which is sending the a message to my server and I am trying to get substrings in order to extract them into variables. I want to use regex for this. Although I have no syntax problems, it will not match. This is the message I am sending and my code.
  " PUT /John\r\n\r\n
  London "
  private StreamReader sReader = null;
  private StreamWriter sWriter = null;
  
  public SocketClass(Socket s)
      {
          socket = s;
          NetworkStream nStream = new NetworkStream(s);
          sReader = new StreamReader(nStream);
          sWriter = new StreamWriter(nStream);
          startSocket();
      }
  String txt = "";
          while (sReader.Peek() >= 0)
          {
              txt += sReader.ReadLine() + "\r\n";
          }
  
          else if (txt.Contains("PUT"))
          {
  
              Console.WriteLine("triggered");
              Regex pattern = new Regex(@"PUT /(?<Name>\d+)\r\n\r\n(?<Location>\d+)\r\n");
              Match match = pattern.Match(txt);
              if (match.Success)
              {
                  String Name = match.Groups["Name"].Value;
                  String Location = match.Groups["Location"].Value;
                  Console.WriteLine(Name);
                  Console.WriteLine(Location);
  
              }
          }
  
  A:
  
  The problem seems to be that while your input has alphanumeric characters your regex is looking for \d which are numeric digits. The regex can be easily changed to this to make it work:
  Regex pattern = new Regex(@"PUT /(?<Name>.+)\r\n\r\n(?<Location>.+)\r\n");
  
  . represents any character. It may be that you could narrow it down more to say the match has to be alphabetic characters or something else but the above will certainly work for your given input.
  
  