Using Regex in C# for ip:port format
-
But this work's fine. MessageBox.Show(System.Text.RegularExpressions.Regex.IsMatch("123a123a123a123", @"^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}:[0-9]{1,5}$", System.Text.RegularExpressions.RegexOptions.ExplicitCapture).ToString()); Thanks!
Develop2Program & Program2Develop
-
Hmmmm not working for 2221.1.1:3000 Sorry!
Develop2Program & Program2Develop
-
You need to escape the '.' else it will match anything.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 beta 1 - out now!
((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x)) -
Sorry make that 123a123a123a123:1
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 beta 1 - out now!
((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))This should work @"^[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[:][0-9]{1,5}$" Thanks!
Develop2Program & Program2Develop
-
This should work @"^[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[:][0-9]{1,5}$" Thanks!
Develop2Program & Program2Develop
Navneet Hegde wrote:
This should work
Rather use \. than [.] . Some regex implementations might see [.] as .
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 beta 1 - out now!
((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x)) -
Navneet Hegde wrote:
This should work
Rather use \. than [.] . Some regex implementations might see [.] as .
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 beta 1 - out now!
((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))Sure thx!
Develop2Program & Program2Develop
-
Hi all, I am using C#.Net 2008. I am using following code to varify proper format (udp ip:port i.e "225.1.1.1:3000") of input string. But it is not working properly. System.Text.RegularExpressions.Regex regStr = new System.Text.RegularExpressions.Regex(@"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}:\d{1,5}"); bool b; b = regStr.IsMatch("225.1.1.1:3000"); //return true b = regStr.IsMatch("2225.1.1.1:3000"); //return true. should return false Anybody knows proper regular expression for ip:port format? Can anyone give me good links for using Regex , regular expression in C#. Thanks in advance. Regards, Aniket A. Salunkhe
I'd just try to open the port and let the framework figure it out.
-
I'd just try to open the port and let the framework figure it out.
PIEBALDconsult wrote:
let the framework figure it out.
and miss all the fun regexing IPv6?
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
Hi all, I am using C#.Net 2008. I am using following code to varify proper format (udp ip:port i.e "225.1.1.1:3000") of input string. But it is not working properly. System.Text.RegularExpressions.Regex regStr = new System.Text.RegularExpressions.Regex(@"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}:\d{1,5}"); bool b; b = regStr.IsMatch("225.1.1.1:3000"); //return true b = regStr.IsMatch("2225.1.1.1:3000"); //return true. should return false Anybody knows proper regular expression for ip:port format? Can anyone give me good links for using Regex , regular expression in C#. Thanks in advance. Regards, Aniket A. Salunkhe
Another thread came up with: @"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}[:][0-9]{1,5}$" But what if you want to constrain the octets to ONLY values from 0 to 255? And what if you really wanna go whole hog and constrain the port to 0 to 65535? I don't know regular expressions that well, so I am curious. Roink
Roink
-
PIEBALDconsult wrote:
let the framework figure it out.
and miss all the fun regexing IPv6?
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
I'm more concerned about, "that which will come after IPv6". Let Microsoft do all the work, that's why I pay them. :-D
-
Another thread came up with: @"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}[:][0-9]{1,5}$" But what if you want to constrain the octets to ONLY values from 0 to 255? And what if you really wanna go whole hog and constrain the port to 0 to 65535? I don't know regular expressions that well, so I am curious. Roink
Roink
-
Roink wrote:
But what if you want to constrain the octets to ONLY values from 0 to 255? And what if you really wanna go whole hog and constrain the port to 0 to 65535?
Then you head over to www.regexplib.com and you do a search[^]
-
As they say in Britain, Brilliant! Everything a growing RegEx coder needs! Thank you! Muchas gracias! Merci beaucoup!
Roink
-
Roink wrote:
As they say in Britain, Brilliant
I think they say that in other countries too, not just here in GB!
No, it's only there. :-D
-
That is true, too. You must also replace all the . with \. So, the regex is "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}$" Take in mind that also the above regex is not absolutely correct. For example, it matches also 999.999.999.999:3000.
-
Another thread came up with: @"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}[:][0-9]{1,5}$" But what if you want to constrain the octets to ONLY values from 0 to 255? And what if you really wanna go whole hog and constrain the port to 0 to 65535? I don't know regular expressions that well, so I am curious. Roink
Roink
Roink, Thanks for the solution. Following is working to check proper ip & port. I found this from regexlib.com. But still need to do varification for port as 0,00,000, etc or 0*.
@"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]):(\d{1,4}|[0-5]\d\d\d\d|[0-5]\d\d\d\d|6[0-4]\d\d\d|65[0-4]\d\d|655[0-2]\d|6553[0-5])$"
Thanks & Regards, Aniket A. Salunkhemodified on Wednesday, December 3, 2008 4:47 AM