title: Parse guids out of a string in powershell
body: <p>I am new to both powershell and guids. All the examples discussed on the web are for validating a guid. I couldn't find examples of parsing a guid pattern out of string. The regex for a guid is </p>
  
  <pre><code>^{[A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}}$
  </code></pre>
  
  <p>Say I have a string with </p>
  
  <pre><code>"This is a sample string with two guids. Guid1 is {FEB375AB-6EEC-3929-8FAF-188ED81DD8B5}. Guid2 is {B24E0C46-B627-4781-975E-620ED53CD981}"
  </code></pre>
  
  <p>I want to parse this string to get the first occurrence of the guid, which is {FEB375AB-6EEC-3929-8FAF-188ED81DD8B5}. How can I do this in powershell. </p>
  
  <p>I tried the following. But it is not working: </p>
  
  <pre><code>$fullString = "This is a sample string with two guids. Guid1 is {FEB375AB-6EEC-3929-8FAF-188ED81DD8B5}. Guid2 is {B24E0C46-B627-4781-975E-620ED53CD981}"
  
  $guid = [regex]::match($fullString, '^{[A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}}$')
  Write-Host $guid.Groups[1].Value
  </code></pre>
  
  <p>Wondering if there is something wrong with the expression or the way I am calling it. </p>