On Thu, 6 Oct 2005 10:47:21 +0200, "Marcel Hug"
<ma******************@ATch.abb.com> wrote:
\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-
9][0-9]?)\b
It works fine for the most cases, but it is possible to insert a string
like:
192.168.23.20-0
How can i fit this failure ?
The other posts assumed that you were matching a single IP. If that is
true you can use their solution. If however you are searching for all
IP adresses in a string you will need to do this.
Assuming RegexOptions.IgnorePatternWhitespace (Which is needed to make
regexs readable) and formatted using a fixed width font:
(?<! \S ) # Look behind assertion that previous character isn't a
non space character
(
(25[0-5] | 2[0-4][0-9] | [01]?[0-9][0-9]?)# A valid number
\. # Followed by a dot
){3} # Repeated three times
(25[0-5] | 2[0-4][0-9] | [01]?[0-9][0-9]?) # The last number
(?! \S ) # Look ahead assertion that next character isn't a non
space character
\b can only find alphanumeric boundries since it is a zero-width
assertion. I replaced those with assertions that look forward and
backward.
For more information look in documentation at the regex language
elements->Grouping constructs. For mor information, this webpage
http://www.regular-expressions.info/lookaround.html explains it in
more detail.
--
Marcus Andrén