Home > Software engineering >  Problem trying to match a word with a letter with accent mark and with "del". REGEX in pyt
Problem trying to match a word with a letter with accent mark and with "del". REGEX in pyt

Time:06-14

I want to match the following three expressions:

"Facultad Regional Villa María"
"Facultad Regional Mar del Plata"
"Facultad Regional Haedo"

This what i did:

"^(Facultad Regional)( [A-Z][a-z]*){1,5}$"

As you can see, Facultad Regional must be at the beginning of the string.

I can match the third expression perfectly. But not the other two. I need the following concept to put in my regex. I need that if the word "del" exists, is still valid. Also, if a word has an alphabet character with an accent mark, it's also valid.

Thanks in advance. I'm glad to read your answers (:

CodePudding user response:

From what you've said, I got these rules

  • String starts with Facultad Regional
  • Then there can be from 1 to 5 following words
    • del
    • word that is title cased and has no more uppercase letters afterwards

That's the regex you want ^Facultad Regional( \p{Lu}\p{Ll} | del){1,5}$

P.S. \p{Lu} and \p{Ll} means letter that has upper(lower)case variant of this letter

  • Related