0

I'm looking to exclude all the words "value" and "id" then match if there is an md5 file, I have the following regex that matches all the MD5 but is not excluding the words I mentioned, example

(?!(value|id)(\":\s\"|':\su'))\b[a-fA-F\d]{32}

I was trying to use a negative lookbehind but python is not accepting it, using Java works perfectly but python is giving me the error "A lookbehind assertion has to be fixed width"

(?<!(value|id)(\":\s\"|':\su'))\b[a-fA-F\d]{32}

I tried with the following regex and works in python but just let me exclude one word ("value" in this example) but is giving me the characters before the md5 and I just want to match the md5, example

((?<!value)\":\s\"|':\su')\b[a-fA-F\d]{32}

Can someone explain me how would be the equivalent in python?

RemDosal
  • 23
  • 4
  • 1
    If you alternate them, they must be of the same length, if this suffices you can use `(?<!lue|_id)` else you need to chain them like `(?<!value)(?<!id)` – bobble bubble Nov 15 '22 at 21:39
  • See [this demo](https://regex101.com/r/apE6ok/1) or [that demo](https://regex101.com/r/j7Bwaj/1) (I further set the [capture group](https://stackoverflow.com/questions/15340582/python-extract-pattern-matches) to the md5). – bobble bubble Nov 15 '22 at 21:46
  • Thanks for the response, your second suggestion kind does the job, but for some reason is matching other character before the md5 value and I'm looking to match just the md5, any idea how to do it? `(((?<!value)(?<!id))(\":\s\"|':\su'))\b[a-fA-F\d]{32}` [example](https://regex101.com/r/SzPzoE/1) – RemDosal Nov 15 '22 at 21:53
  • 1
    Use [`re.findall`](https://docs.python.org/3/library/re.html#re.findall), see [this Python demo at tio.run](https://tio.run/##lVLLTsMwELznK4IvSaQWtXk1qUCICz@BkeXY68ZgnGA7FRXw7cFpqNQjOe3K45nZV39ybaezcZTvfWdcaCAIHFhHrDPhfRgjjI5UDYDRPsQIRLFtIC82Jd/xtNrRhlUsLYGWLK8LUWK08r8G8ioN9QrUDXYmXoCPgRoHhjDVWeDXmJAKSEttu8QJLKOKOtnpmbX58@k7TWjfm87XPiM@ZzA5TjjrjIGZRyRfYshOja/@TSpFWEv1YdFc7MkutBtIM1ipwVpiwRwlg@uRcb8nqf/a6P@vO0TnlUK092nNmzoVm4o3uaiLbZ5mrNrxKhdZXW5rEBHWKAkCAwf49AdhUPxwd3PmJ1MmuQ977439pr8jH4YowU38TNficf2E@ctXlv4kaFKwEx9uhdScKhWfJVfh5dq8SW@kdv7dJuP4Cw). – bobble bubble Nov 15 '22 at 21:59

0 Answers0