0

I have to match entirely all passwords containing at least four successive uppercase letters not immediately preceded by two or more successive digits. My initial method of doing this was to use (?<!\d{2,}), but I got an error from re as it was a variable length negative lookbehind.

I have checked and can't find any solution to this on similar questions, as the usual advice is to just use the regex module, which is not an option for me. Additionally most other answers refer to using * and +, which isn't applicable for my problem. I've tried many variations of this but can't seem to get it to work.

The code I am using is below:

re.findall(r'((?<!\d){2,})([A-Z]{4,})

Hunter1471
  • 11
  • 3
  • Can you install PyPi regex module? If yes, the problem is solved. Go to the terminal/console, `pip install regex`. Then replace all `re` with `regex` references. – Wiktor Stribiżew Nov 13 '20 at 13:21
  • "not immediately preceded by two or more successive digits" - the "or more" is redundant. Any position preceded by more than two successive digits is preceded by two successive digits. – user2357112 Nov 13 '20 at 13:26
  • @WiktorStribiżew Ah, sorry, should've specified. I'm working on a remote computer with limited permissions. I can only edit a Python text file to solve a problem. – Hunter1471 Nov 13 '20 at 14:01
  • @user2357112supportsMonica Thanks, I'd already tried that but I'm doing some virtual labs so it isn't accepting it as a correct answer. Do you think I've done the rest of the expression correctly? It doesn't seem like I've made a mistake so it looks like I need to find a way to actually get the 2 or more somehow. – Hunter1471 Nov 13 '20 at 14:02
  • Then just use `(?<!\d{2})`, if you do not want to match strings preceded with 2 or more digits, just "two" is already satisfying a condition. Probably add a letter boundary, `r'(?<!\d{2})(?<![A-Z])[A-Z]{4,}'`. Please supply some examples in the question itself. – Wiktor Stribiżew Nov 13 '20 at 14:02

0 Answers0