regex match for string in Xml file

Welcome Forums General PowerShell Q&A regex match for string in Xml file

Viewing 1 reply thread
  • Author
    Posts
    • #274692
      Participant
      Topics: 11
      Replies: 32
      Points: 95
      Rank: Member

      Hi folks. I almost had this project wrapped up but got stuck with some odd XML file string match issue. I have the correct Regex code below to capture the 2 items below. But the problem i have is any single XML file we parse thru, may have either of the two xml element values in them. To explain clearly, the 1st XML snippet below ending with “bravo2.gif” is followed by a > character (NO empty spaces). The 2nd XML snippet further below ending with “FaxDoc1.jpg” is followed by a single space and /> characters. The problem i’m trying to figure out is how to combine the two Regex code so that when parsing thru XML files, the pattern search will now how to look for either Regex queries and pickup only the string between the double quotes, so the value for xlink:href. The hundreds of XML files, may have image references that either have a space or they do not (like 2 examples below). Thanks for any assistance.

       

      $xmlDoc.InnerXml | Out-String | % {[Regex]::Matches($_, “(?<=ext-link xlink:show=””embed”” xlink:href=)((.|\n)*?)(?=>)”)} | % {$_.Value}

      <ext-link xlink:show=”embed” xlink:href=”../../../Content/images/bravo2.gif”>

       

      $xmlDoc.InnerXml | Out-String | % {[Regex]::Matches($_, “(?<=ext-link xlink:show=””embed”” xlink:href=)((.|\n)*?)(?=\s/>)”)} | % {$_.Value}

      <ext-link xlink:show=”embed” xlink:href=”../../../Content/images/FaxDoc1.jpg” />

    • #274701
      Participant
      Topics: 11
      Replies: 32
      Points: 95
      Rank: Member

      Moderators – please delete this. The issue resolution was not Regex related, used TrimEnd(‘ /’) to fix the problem at hand. Thanks

Viewing 1 reply thread
  • You must be logged in to reply to this topic.