title: oracle regex functions to format us phone numbers
body: <p>I'm trying to format us phone numbers using Oracle regular expression. </p>
  
  <p>I have to use below conditions </p>
  
  <ol>
  <li>if count of digits &lt; 10 then null </li>
  <li>if count of digits = 10 then format the phone number as 111-111-1111</li>
  <li>if count of digits > 10 and has a plus sign at the front then format the 
   digits by skipping first digit after plus sign as 111-111-1111</li>
  <li>if count of digits > 10 and has no plus sign at the front then format the first 10 digits as 111-111-1111</li>
  </ol>
  
  <p>See examples below for all 4 cases  </p>
  
  <pre><code>+(555)                     --&gt; NULL
  1112223333                 --&gt; 111-222-3333
  +1 (123) 1111111 x1111     --&gt; 123-111-1111
  (111)1111111 Ext. 1111     --&gt; 111-111-1111
  (111) 111-1111 ext 1111    --&gt; 111-111-1111                 
  2 111-111-1111             --&gt; 211-111-1111
  </code></pre>
  
  <p>Thank you for your help. </p>