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

FutureWarning: Possible nested set at position 1 Error Python

I was working on something and at some point, I needed to check whether the string satisfies this:
The string must contain at least 5 words and each separated by a hyphen(-) or an underscore(_).
Here is the code that I wrote:

password=eval(input('Password:'))
pattern=r'[[\w][-_]]{5,}'
import re
re.fullmatch(pattern,password)

But it gives ‘ ipython-input-32-7c87b09218f8>:4: FutureWarning: Possible nested set at position 1
re.fullmatch(pattern,password) ‘ error. Why that happens, any idea?Thanks in advance.Btw I’m using Jupyter notebook.

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

>Solution :

You can match 1+ word characters, and then repeat at least 4 times matching either _ or / and again 1 or more word characters.

\w+(?:[/_]\w+){4,}

Explanation

  • \w+ Match 1+ word characters
  • (?: Non capture group to repeat as a whole part
    • [/_] Character class matching either / or _
    • \w+ Match 1+ word characters
  • ){4,} close the no capture group and repeat 4 or more times

See a 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