title: How can I use Regular Expression to format an ID?
body: <p>I have got a fairly challenging set of requirements.</p>
  
  <p>I have an ID with various combinations of digits, spaces and characters and would like to match and replace certain characters using regular expressions.</p>
  
  <p>Here are the requirements:</p>
  
  <ol>
  <li><p>IF the ID contains all digits and no characters, then we need to insert a space after the 2nd digit. Example, assume the ID is 12384499003833. After inserting a space after the second digit, the new value should be 12 384499003833.</p></li>
  <li><p>Taken the same ID value of 12384499003833, if the the 3rd character is a D or N, then there should be no space. The value should look similar to this: 12*<em>N</em>*84499003833.</p></li>
  <li><p>Again, using same value as an example, if the 10th <em>and</em> 11th characters are GG, then insert 2 spaces before GG. When the 2 spaces are added, the new value should look similar to 123844990  *<em>GG</em>*833</p></li>
  <li><p>and final requirement: If the 3rd character is D or N and the 10th and 11th characters are GG, there should be no space after 2nd digit but 2 spaces after GG.
  Example output should look similar to this: 12*<em>D</em>*844990  *<em>GG</em>*03833</p></li>
  </ol>
  
  <p>I am truly sorry but I am really stumped.</p>
  
  <p>Your assistance is greatly appreciated.</p>
  
  <p>Here is a table of input values and their formatted output values</p>
  
  <pre><code>Input            | Output
  12384499003833   | 12 384499003833
  12N84499003833   | 12N84499003833
  12D84499003833   | 12D84499003833
  123844990GG833   | 12 3844990  GG833
  12N844990GG833   | 12N844990  GG833
  12D844990GG833   | 12D844990  GG833
  
  $tid = $_GET["tid"];
  
  // Connect to SQL Server database
  include("../connections/TDConnect.php");
  
  $tsql = "SELECT * FROM TC(dtops.dbo.tSearch, Name, '\"$tid*\"')";
  </code></pre>