title: How to find and extract a substring from a command output?
body: <p>Before I go into details I'd like to stress the fact that using PowerShell is not an option, because the script is supposed to be run on machine where PowerShell might not be available.</p>
  
  <p>I need to check for a version of Internet Explorer installed on a Windows machine and act upon it depending on which version it is.</p>
  
  <p>So far my batch script looks like this:</p>
  
  <pre><code>@echo off
  setlocal
  for /f "tokens=*" %%a in ( 'reg query "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer" /v Version' ) do ( set IEVerReg=%%a )
  endlocal
  </code></pre>
  
  <p>As you can see I am assigning <code>reg query</code> output to IEVarReg variable. The ouput is different on different Windows versions, examples:</p>
  
  <p>Windows XP:</p>
  
  <pre><code>! REG.EXE VERSION 3.0
  
  HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer
      Version     REG_SZ  8.0.6001.18702
  </code></pre>
  
  <p>Windows 7:</p>
  
  <pre><code>HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer
      Version    REG_SZ    9.0.8112.16421
  </code></pre>
  
  <p>Ideally, I'd like to get the first digit from the version number and do something like:</p>
  
  <pre><code>if
    version == 8
  then
    execute this
  elseif
    version == 9
  then
    execute that
  </code></pre>
  
  <p>I'm sure I'll figure out how to do the <code>if</code> part once I get the version number, but it's the getting version number part I cannot figure out. I could do it easily in bash, perl, etc. but have no idea about Windows Command Line.</p>
  
  <p>Help would be hugely appreciated.</p>
  
  <p>PS. I'v seen <a href="http://www.windowsitpro.com/article/internet/jsi-tip-8332-how-can-i-use-the-command-line-to-determine-the-version-of-internet-explorer-that-is-installed-" rel="nofollow">Jerold Schulman's script</a> but it returns the whole version number which is too much for me.</p>