Reg. exp. question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I need to check a string for valid characters. The regular expression that I
am working is long and I try to make it short. There are many 'or' condition
in the expression, so if I can find answer to the following question then I
can make the reg exp shorter and nicer.
Now example: There is a word that could be 2 or 3 characters. First
characters should be "a" and the last character should be "d". The middle
character is either "n" or nothing. My regular expression looks like:
[a][n][d]|[a][d]
Is there a way to make the "d" optional as character d or nothing and not
use (|).
Thanks in advance,

Roy
 
Don't know if this will make it any shorter.
an{0,1}d

{0,1} specifies that the expression will accept 0 or 1 occurances of the
preceding character or expression.

Hope this helps

Jacques
 
Back
Top