<p>I generally stay away from <code>regular expressions</code> because I seldom find a good use for them. But in this case, I don't think I have choice.  </p>

<p>I need a regex for the following situation.  I will be looking at three character strings. It will be a match if the first character is <code>1-9 or the letters o,n,d (lower or upper)</code>  AND the second character is <code>1,2 or 3</code> and the third character is <code>0-9</code>.</p>

<p>Can anybody help me out?</p>

```
```
[1-9ondOND][123][0-9]
```
```
I omitted the
```
^
```
and
```
$
```
(beginning and end of string markers) because you said you'd have three-character strings, but there's no harm in including them, and they may improve speed, not that that'll be a big deal on such short input.
Of course, this assumes you're working in a language and locale where the uppercase equivalent of
```
o
```
,
```
n
```
, and
```
d
```
are
```
O
```
,
```
N
```
, and
```
D
```
. If not, you'll need to tell your regex interpreter to ignore case. The mechanism varies by language/framework.
For python, you'd use something like:
```
```
re.match('[1-9ond][123][0-9]', inputstring, re.IGNORECASE)
```
```
The
```
re.match
```
forces a match at the beginning of string, so you wouldn't need the
```
^
```
in any case.