I am trying to write a regex that matches all numbers (0-9) and # @ % signs.
I have tried ^[0-9#%@]$ , it doesn’t work.
I want it to match, for example: 1234345, 2323, 1, 3@, %@, 9, 23743, @@@@@, or whatever…
There must be something missing?
Thank you
You’re almost right… All you’re missing is something to tell the regular expression there may be more than once of those characters like a
*(0 or more) or a+(1 or more).The
^and$are used do indicate the start and end of a string, respectively. Make sure that you string only contains those characters otherwise, it won’t work (e.g. “The number is 89#1” wouldn’t work because the string begins with something other than 0-9, #, %, or @).