Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python "look-behind requires fixed-width pattern" – Regular Expression Error

I have this regex, it matches a certain word if a list of word are not found:

(?<![Yy]ellow |[Bb]lue |[Rr]ed |[Pp]urple |[Bb]lack )[Cc]olor

It works, but I get the Regex Expression Error: "look-behind requires fixed-width pattern".
I do not have access to the python code.
I tried delimiting by (?:^ and |$) as I saw in a similar question but it didn’t work.
I also found this answer that I think solves the problem but I don’t understand how to make it work in my case.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Test HERE

Dark Color          #match
light color         #match
Blue Color
red color
that is a blue color and theme
opaque color        #match
purple color

>Solution :

You can split up the alternatives in the lookbehind with separated loopbehind assertions if you want a match only:

(?<![Yy]ellow )(?<![Bb]lue )(?<![Rr]ed )(?<![Pp]urple )(?<![Bb]lack )[Cc]olor

See a regex demo

If you have no control over the Python code, you might check if matching what you don’t want and returning a capture group for what you do want also works:

(?:[Yy]ellow |[Bb]lue |[Rr]ed |[Pp]urple |[Bb]lack )[Cc]olor|([Cc]olor)

Regex demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading