I need to find all data matching with string who looking like this :
16041917
16041917-A
16041917-Z
So as you can see sometimes I can get -X suffix or sometimes no.
In my code I have the value of the number but I don't know if there is a suffix or not. So I try to make a regex to find if the number exist in my database.
{number : {$regex: "^16041917|^-[A-Z]$"}}
It works but I don't know if my regex will work for everything. Can you tell me if you have better ?
"^[0-9]{8}(?:-[A-Z])?$"16041917(-[A-Z])?$41917(-[A-Z])?$and I want the exactly number[0-9]because in your initial question you said you wanted to match18689784and18689784-G. To only match specific number, just use it instead of[0-9]{8}."^16041917(?:-[A-Z])?$"