I need a C # regular expression that will match an IP subnet, such as "127.65.231", but does not match an IP address on the subnet, such as "127.65.231.111". I found this regex for the IP address:
@ "\ B \ r {1,3}. \ D {1,3}. \ D {1,3}. \ D {1,3} \ b"
and thought that I can just delete the part that checks the last octet, for example:
@ "\ B \ r {1,3}. \ R {1,3}. \ R {1,3} \ b"
but this matches both the IP address and the subnet. Can anyone help with this?
@"^\d{1,3}\.\d{1,3}\.\d{1,3}$"
use Line Anchors. Add ^ to the beginning of your Regex and $ at the end to check the beginning and end of the input.
This will correspond to 127.65.231 , but not 127.65.231.111
127.65.231
127.65.231.111
You can try using lookahead. Also, avoid characters . : - otherwise it will match any character:
.
@"\b\d{1,3}\.\d{1,3}\.\d{1,3}(?=\.\d{1,3})\b"
This will match any string, such as 127.65.231 , if accompanied by a string of type .111 .
.111
Source: https://habr.com/ru/post/1494569/More articles:Running MSVC via CMake using ssh in Cygwin works if you use a password to log in, but not with a public key - windows-7MVC4 AllowHtml does not work with the dictionary - c #JAXB does not create member variables and recipients and setters - javaRemoving strings with multiple keys in pandas - pandasUsing Devise in engine mounted rails outside the engine - ruby-on-railsConvert TIFF images to Javascript - javascriptHow to overload assignment operator for writing in Delphi - assignment-operatorIs there an HTML5 method for displaying tiff image data already loaded into memory - javascriptC # Convert or parse a variable in DateTime - c #Is there a way to use a property similar to a behavior? - propertiesAll Articles