2

I'm trying to parse a number of log files for IP addresses using PowerShell, but within those files I also have a number of false positives which are actually version numbers. There may be more but as a first start I wanted to grab all IPs that are not preceded by Version=.

I've tried a number of different variations of my Regex with no real success and hacking around in regex101.com has also given me no fruits.

(?<!Version=)(?<Address>((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]?))

Ideally it should be something like:

  • Not Match Version=10.0.0.1

  • Match 10.0.0.1

  • Match IPAddress=10.0.0.1
  • Match IP=10.0.0.1

etc.

1
  • 1
    Please edit the question and add a few samples of data that should be matched and that shouldn't. Whilst at it, remove any powershell-version tags, as those should be used when the issue is about a specific version. Commented Apr 25, 2019 at 11:47

1 Answer 1

4

Add word boundaries (\b):

(?<!Version=)\b(?<Address> ... )\b

This prevents the match from starting within the IP address, which would otherwise happen. Without word boundaries, the area in square brackets would be a match: Version=1[0.0.0.1]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.