title: Get a substring from a Windows batch variable
body: <p>In a batch file I have a variable containing an IP. Just for example:</p>
  
  <pre>SET ip = 170.150.120.10</pre>
  
  <p>I would like to define another variable, replacing the last octet with 1, which in the example would be <code>170.150.120.1</code>.</p>
  
  <p>The IP may change (it is defined dynamically), varying in its length, so capturing a fixed length substring and concatenating it would not work anytime (in the example it would be <code>SET baseIP = %ip:~0,9%.1</code>).</p>
  
  <p>How can this task be solved?<br />
  Is there some RegEx support in Windows command line?</p>