Regular Expression for AlphaNumeric, Hyphen and Underscore without any space

I would like to have a regular expression that checks if the string contains Alphanumerics, Hyphen and Underscore. There should not be any spaces or other special characters other these three. My string will be under either of these 2 patterns.

  • ‘XYZ0123_123456’
  • ‘ABCdefGHI-727’

I have already tried this expression. But it didnt workout. [[a-zA-Z0-9_-]*]

Source: java

Leave a Reply

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