Q:

Dynamic Regex for number range using c#

I'm looking at UK postcodes and trying to work out how I can take data from a database (the first part of a UK postcode) and dynamically create a regexp for them using c#. For example:
AB44-56

I know what I want as an output:
AB([4][4-9]|[5][0-6])+

However, I can't work out how I might be able to do this with logic, perhaps I need to split the Letters from the numbers first, but i can't do that using split.
I have other combinations too - single range:
AB31 would be AB[3][1]+

Some with just letters:
BT would be BT+

Some with a single letter and 1 or two numbers:
G83 Would be G[8][3]

Any suggestions or guidance would be very much appriciated how this may be coded.

A:

afrom wikipedia UK postal codes : 

This can be generalised as: (one or two letters)(number between 0 and
  99)(zero or one letter)(space)(single digit)(two letters)

so
^[A-Z,a-z]{0,2}\d+[A-Z,a-z]?\s\d[A-Z,a-z]{2}$

might work.
EDIT: Also if you are trying to restric the postal codes to say those with the same prefix as the ones in the database you could do this.
var source = "BTasdfweasdf"; //from the database
var input = "BT1A 1BB"; //from the somewhere else
var regex = Regex.Replace(source, @"(^[A-z,a-z]{0,2})(.*)", @"$1\d+[A-Z,a-z]?\s\d[A-Z,a-z]{2}$");
var match = Regex.Match(input,regex); 

