Regex matching multiple spaces/dashes in String

I have an input that has to be uppercase (with unicode support), and that can contain multiple spaces or dashes - (and that should start and end with letters).

I have made this regex : /^[p{Lu}]+s*-*[p{Lu}]+$/

As seen here, this matches everything I need unless it contains multiple dashes or spaces (ABC DEF and ABC-DEF work, but AB-CD-EF and AB CD EF don’t work).

I am still a beginner with regex so please bear with me 🙂

Thanks in advance,

Coloco


Source: regex

Leave a Reply