Coloco
Coloco

Reputation: 353

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

Upvotes: 2

Views: 286

Answers (1)

vks
vks

Reputation: 67988

^[\p{Lu}]+(?:\s*-*[\p{Lu}]+)+$

          ^^               ^^

Try this.See demo.Make the group accept 1 or more.

https://regex101.com/r/yW3oJ9/7

Upvotes: 2

Related Questions