Arghhhhh I frigin hate regex!!! Whoever designed regex did it in the most impossible illogically way he could have.
Ok so, I'm enhancing a program I made. The program is to connect to a CoD4 server with a string the user inputs into a text field. The string will look like this:
/connect 1.2.3.4:12345; password blah
This is the correct way to make the string. But I want my program to be able to correct mistakes in the string. For example, say they miss the semi colon after the port, or misspell the word password...etc.
So what I'm trying to do right now is checks to make sure each segment is correctly inputted. I'm having some trouble here, because regex just makes no sense to me.
So here is my test method for testing the regex:
This code is supposed to check to make sure the IP contains only integers, and is formatted like an IP should be (111.222.333.444).
I want this particular regex to do the following:
-Ensure that each segment in the IP is ONLY a number (in my code, you can randomly stick letters in there for some unknown-to-me reason)
-Ensure that each segment in the IP contains only 1-3 numbers
-Ensure that the IP is formatted as such: 111.222.333.444
I won't ask ya'll to write the whole regex portion of this program, but I'm hoping that if you can show me how to do this part that I can pick up on the rest. And yes I've tried going to regular-expressions.com and yeah... it just doesn't make any sense to me. I do what I think is the logical way and it doesn't work.
Sorry for long post, I tend to get carried away.
Ok so, I'm enhancing a program I made. The program is to connect to a CoD4 server with a string the user inputs into a text field. The string will look like this:
/connect 1.2.3.4:12345; password blah
This is the correct way to make the string. But I want my program to be able to correct mistakes in the string. For example, say they miss the semi colon after the port, or misspell the word password...etc.
So what I'm trying to do right now is checks to make sure each segment is correctly inputted. I'm having some trouble here, because regex just makes no sense to me.
So here is my test method for testing the regex:
Code:
private void match()
{
String input = this.input.Text;
Regex pattern = new Regex("[0-9].[0-9].[0-9].[0-9]");
if (input != "")
{
if (pattern.IsMatch(input))
{
this.isMatch.Text = "Match";
}
else
{
this.isMatch.Text = "Not Match";
}
}
}
This code is supposed to check to make sure the IP contains only integers, and is formatted like an IP should be (111.222.333.444).
I want this particular regex to do the following:
-Ensure that each segment in the IP is ONLY a number (in my code, you can randomly stick letters in there for some unknown-to-me reason)
-Ensure that each segment in the IP contains only 1-3 numbers
-Ensure that the IP is formatted as such: 111.222.333.444
I won't ask ya'll to write the whole regex portion of this program, but I'm hoping that if you can show me how to do this part that I can pick up on the rest. And yes I've tried going to regular-expressions.com and yeah... it just doesn't make any sense to me. I do what I think is the logical way and it doesn't work.
Sorry for long post, I tend to get carried away.