regexcharacterdigit

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?


Solution

  • 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*-]