A regex to match strings with alphanumeric, spaces and punctuation

后端 未结 3 1411
既然无缘
既然无缘 2020-12-15 19:25

I need a regular expression to match strings that have letters, numbers, spaces and some simple punctuation (.,!\"\'/$). I have ^[A-Za-z0-9 _]*[A-Za-z0-9

3条回答
  •  没有蜡笔的小新
    2020-12-15 20:07

    Just add punctuation and other characters inside classes (inside the square brackets):

    [A-Za-z0-9 _.,!"'/$]*
    

    This matches every string containing spaces, _, alphanumerics, commas, !, ", $, ... Pay attention while adding some special characters, maybe you need to escape them: more info here

提交回复
热议问题