Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
56
rated 0 times [  63] [ 7]  / answers: 1 / hits: 56086  / 13 Years ago, mon, august 29, 2011, 12:00:00

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][A-Za-z0-9 _]*$ and it works well for alphanumeric and spaces but not punctuation. Help is much appreciated.


More From » regex

 Answers
-1

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


[#90361] Friday, August 26, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
charisma

Total Points: 1
Total Questions: 99
Total Answers: 117

Location: Thailand
Member since Thu, Apr 22, 2021
3 Years ago
;