I was creating a regex for following condition
a string can contain any alphabet, digit and ‘ and ?
the string should start with either alphabet or digit
for ex:
adsfj
asfj's
jfkd'sdf?
df
ds?
afjdk?
are all valid
I use C# 2.0
I tried something like this
^[a-zA-Z0-9]+[']\*[a-zA-Z0-9]\*[?]\*[a-zA-Z0-9]\*$
which did not solve the problem…. any idea..?
It’s simpler than you made it:
^[a-zA-Z\d][a-zA-Z\d'?]*$If you allow underscores with your other characters, it can be simplified to:
^\w[\w'?]*$