I am new with Regex and I have almost got it working. I think I make a small noob mistake and I have already looked through documentation.
I have a little script that I run twice, each time for a different string. The first string does what I want. The second doesn't. Somehow it seems that the old value of the first run is placed in front of the values after the second run. It is best to explain when I show my code and output.
Original script where a TCPclient callback should first give BS=63
and then RLs=1
.
private void Main()
{
EditString(TCPclientCallback1);
EditString(TCPclientCallback2);
}
private void EditString(string response)
{
Regex rgxLetters = new Regex(@"[\d]");
Regex rgxNumbers = new Regex(@"[^\d]");
Console.WriteLine(response);
Console.WriteLine(rgxLetters.Replace(response, ""));
Console.WriteLine(rgxNumbers.Replace(response, ""));
Console.WriteLine();
}
output
BS=63
BS=
63
RLs=1
RLs=
631
The last value needs to be 1
instead of 631
. In the next example I manually insert the desired string.
private void Main()
{
EditString("BS=63");
EditString("RLs-1");
}
private void EditString(string response)
{
Regex rgxLetters = new Regex(@"[\d]");
Regex rgxNumbers = new Regex(@"[^\d]");
Console.WriteLine(response);
Console.WriteLine(rgxLetters.Replace(response, ""));
Console.WriteLine(rgxNumbers.Replace(response, ""));
Console.WriteLine();
}
output. This is the desired output
BS=63
BS=
63
RLs=1
RLs=
1
That would mean that there is no issue in the regex part.
In my application I get my response
from the callback of a TCP client. So somehow that callback is not purely BS=63
or RLs=1
EDIT2
The callbacks of my TCP client were wrong... The Regex part is working just fine. So my question ended up to be irrelevant. Sorry for that!! Thanks anyways for all the quick responses :)