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,


Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.