How to allow angular brackets <> without any characters/space between them using javax regex?Current pattern is like below:
"^[A-Za-z0-9\\s-_]*[A-Za-z0-9][A-Za-z0-9\\s-_]*$"
Use the | token to create an alternative (match this or that).
^(?:[A-Za-z0-9\s-_]|<>)*[A-Za-z0-9](?:[A-Za-z0-9\s-_]|<>)*$
I changed both the [A-Za-z0-9\s-_]+ at the start and end to (?:[A-Za-z0-9\s-_]|<>)*, which means "match 0 or more times [A-Za-z0-9\s-_] or <>".
[A-Za-z0-9_] can be simplified to \w, so a shorter version of the above would be:
^(?:[\w\s-]|<>)*[A-Za-z0-9](?:[\w\s-]|<>)*$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With