0

I have searched within SO and found out several regular expressions to be used to include ONLY THESE a-z A-Z 0-9 - _. So far what I have tried was this one, /[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s. What this actually did was it did not exclude brackets {} [] and parenthesis (). I am not very experienced with regex, heck I don't fully fathom the whole meaning, structure/format of it so can somebody provide me the exact regex which I am looking for? Thanks for the time.

Tsukimoto Mitsumasa
  • 973
  • 4
  • 17
  • 38

2 Answers2

3

Here it is :

  ^[a-zA-Z0-9_-]{1,}$

Will check Any word of at least one letter, number , _ or -

Here is the tutorial for basic REGEX.

Harshal Mahajan
  • 3,310
  • 8
  • 35
  • 66
1

This should do the trick

/^[\w\-]+$/

RoyHB
  • 1,603
  • 18
  • 36