I'm trying to write a regular expression that defines all words written in lower case characters and digits that begin with a digit, end with a digit and contain total of 4 digits.
My idea is :
$[0-9](\varepsilon |[0-9])[a-z]^{*}(\varepsilon |[0-9])[a-z]^{*}[0-9]$
Is my solution correct ? If not , what would be a correct one ?
It’s not quite correct: you want
$$[0-9][a-z]^*[0-9][a-z]^*[0-9][a-z]^*[0-9]\;.$$
The first and last instances of $[0-9]$ ensure that you get your leading and final digits, and the other two ensure that you get exactly four digits altogether. The three instances of $[a-z]^*$ allow any number of lower-case letters (including none at all) to intervene between any two adjacent digits.
Your expression has two major problems. First, it fails to allow for letters between the first two digits, so it cannot match $1a2b3c4$, for instance. Secondly, your inclusion of the empty word as in the sub-expressions $\epsilon\mid[0-9]$ means that your regular expression matches strings with only two or three digits, like $12$.