Search code examples
regexunicodefrench

Regex for french characters fails validation based on the position of french character


In my code I had a Password RegEx (written by someone) (/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[\x20-\x7E]{8,40}$/) which was not supporting french characters. And I modified it a bit to support french characters. And /^(?=.*[a-z])(?=.*[A-Z])(?:.*[àâäæèéêëîïôœùûüÿçÀÂÄÈÉÊËÎÏÔŒÙÛÜŸÇ]*)(?=.*\d)[\x20-\x7E]{8,40}$/ is the new RegEx. But this one does not work as expected. The behavior changes with the position of the french character. For example, NewàTest123! - works and NewTàest123! does not works

Any thoughts on why it fails when the position of the character changes?


Solution

  • Working regex:

    ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[\x20-\x7EàâäæèéêëîïôœùûüÿçÀÂÄÈÉÊËÎÏÔŒÙÛÜŸÇ]{8,40}$
    

    Thanks to @Wiktor Stribiżew