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

Explanation of regexp multiple lookahead behavior

Please help understand why r'\b\w+(?=\d)(?=[A-Z])' does not match Python3A.

It says r'\b\w+(?=\d)(?=[A-Z])' search for words followed by a digit and then by a capital letter. Python3A consists of a word Python followed by a digit 3 and a capital letter A. If the statement is correct, then it should match Python.

Multiple Positive Lookaheads
enter image description here

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 :

It doesn’t match because you have two lookaheads in the same place, one of which asserts a number, and the other asserts a capital letter. Since there is no overlap between those, one of them can’t be true and so the match fails. What you need is just a single lookahead for a digit followed by a capital letter:

\b\w+(?=\d[A-Z])

Regex demo on regex101

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