title: Regex in SQL to match Address
body: <p>I have an SQL table with customer demographics details like <code>Name, Age, Address</code> etc.</p>
  
  <p>In address details there are four fields: 'Address1', 'Address2', 'Address3' and 'PostalCode'`.</p>
  
  <p>I have to write a regex to identify matching cases, which is one of these fields having a number.</p>
  
  <p><strong>Example:</strong></p>
  
  <p><strong>#03-04 and postal code with 6 numeric digits.</strong></p>
  
  <pre><code>Input:
   Address 1:BLOCK VENUE #03-03 
   Address  2:SINGAPORE 177562
  Output:
  Valid(it should be counted by my regex statement)
  </code></pre>
  
  <p>The sample SQL regex I wrote:</p>
  
  <pre><code>select count(distinct cusID) 
  from CustomerTable 
  where Address1 like '%[#][0-9]{1,2}-[0-9]{1,4}%[0-9]{6}';
  </code></pre>
  
  <p>The result obtained is '0' when I use <code>{n}</code> in my regex. If I give manually the condition like <code>[0-9][0-9]</code> (for 6 times) it is working fine.</p>
  
  <p><strong>Problems:</strong></p>
  
  <ol>
  <li><p>Postal code and unit code and postal code can be in any field, ie address1 or address2 or address3. How to parse and count the valid cases?</p></li>
  <li><p><code>[0-9]{6}</code> is not working. For unit code it can be 2 to 5 numeric digits. How to write the regex?</p></li>
  </ol>
  
  <p>Is there any way I can correct my regex so to obtain all customers count with valid address, ie that have a valid unit code (mandatory starts with '#' and followed by numbers and with dash) and postal code (6 digits)?</p>
  
  <p><strong>Example 1:</strong></p>
  
  <pre><code>unit code :#03-067 postal code:096754
  unit code :#03-0698 postal code:113452
  </code></pre>
  
  <p>Please provide your valuable suggestion.</p>
  
  <p>PS: Same working code in Scala:
      .<em>(#[0-9]+-[0-9]+).</em>([0-9]{6}).*</p>
  
  <p>Thanks</p>
  
  <p>Devi</p>