1

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
  • 541
  • 4
  • 19
  • 42

2 Answers2

6

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
  • 3,562
  • 9
  • 36
  • 65
1

This should do the trick

/^[\w\-]+$/

RoyHB
  • 1,715
  • 1
  • 22
  • 38