-1

I would like to create a regex pattern that does not match multiple negative look behind patterns.

But if I try to compile a pattern like

import re
split_pattern = re.compile("(?<!AA|BAB|CAC|JHGS)[1-3]\s*(?=[A-Z])")

I get the error error: look-behind requires fixed-width pattern

Do you know a work-around this problem?

0

1 Answer 1

0

You should just be able to split up the negative lookbehind into multiple lookbehinds like so

(?<!AA)(?<!BAB)(?<!CAC)(?<!JHGS)[1-3]\s*(?=[A-Z])

Edit: As mentioned below in the comments, since BAB/CAC are the same size you could take those together

(?<!AA)(?<!BAB|CAC)(?<!JHGS)[1-3]\s*(?=[A-Z])
Sign up to request clarification or add additional context in comments.

1 Comment

Or (?<!AA)(?<!BAB|CAC)(?<!JHGS), because of same length.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.