0

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 (:

anubhava
  • 761,203
  • 64
  • 569
  • 643

1 Answers1

1

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

UPD: to use \p in your regex, you need to use regex library

sudden_appearance
  • 1,968
  • 1
  • 4
  • 15