Quote:
Originally Posted by kmote Add a word boundry \b to the end. |
Thanks, that worked for letters, but the following characters are still allowed: ? / . , + = - ! ' " ; : ( ) [ ] { } \ | ` ~
All of those characters, if used after a number, matches. I know that in regex, it makes more logical sense in these situations to only match what you WANT it to look like, and not match everything else. So, how do I do that in this case?
My code now:
Code:
Regex pattern = new Regex(
@"(?<First>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?<Second>2[0-4]\d|25"
+ @"[0-5]|[01]?\d\d?)\.(?<Third>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?"
+ @"<Fourth>2[0-4]\d|25[0-5]|[01]?\d\d?)\b",
RegexOptions.IgnoreCase
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);