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
  • 1,001
  • 4
  • 19
  • 40

2 Answers2

5

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,450
  • 8
  • 36
  • 68
1

This should do the trick

/^[\w\-]+$/

RoyHB
  • 1,643
  • 1
  • 21
  • 37