user3748973
user3748973

Reputation: 459

regular expression match digit and characters

How can I create a regex expression that will match only characters and numbers?

this regex matched width digit: /\D/g

how can add characters like - , _ , * and etc to it?

Upvotes: 2

Views: 25443

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

To match Only letter and numbers,

[A-Za-z0-9]

Add the characters you want into the above character class to match also that specific characters.

[A-Za-z0-9_*-]

You could reduce the above regex to,

[\w*-]

Upvotes: 6

Related Questions