0

I would like to ignore the carriage-return line-feeds on the match, but keep them in what is selected. The "." symbol is defined as "matches any character except newline".

The following sample gives the desired results when the `n is removed. I want the XML Partner Tag. I was parsing in XML, but my output didn't seem to be compatible with the utility I'm using (BizTalk Import Binding for Parties).

$bindings = "starting stuff <Partner> more stuff <Name>CompanyName`n</Name> other things </Partner> ending stuff" 

$partner = "" 
$found = $bindings -match "(<Partner>.*<Name>CompanyName</Name>.*</Partner>)"

if ($found) 
{
    Write-Host "matched"
    $partner = $matches[1]
}

Write-Host "partner=$partner "

I have also tried this:

$found = $bindings -match "(<Partner>[.\r\n]*<Name>CompanyName</Name>[.\r\n]*</Partner>)"
NealWalters
  • 14,090
  • 34
  • 109
  • 199
  • My question is to specific to Powershell, the question you pointed me to was vague and used language like "there should be a modifier" – NealWalters Aug 10 '18 at 20:16
  • This seems to be the correct answer: $found = $bindings -match "(?s)(.*CompanyName.*)" - If you want to mark it a dup, at least point to a question that has the answer: https://stackoverflow.com/questions/27680097/what-does-ms-in-regex-mean – NealWalters Aug 10 '18 at 20:30
  • The magic phrase to google is "powershell regex pattern modifiers" – NealWalters Aug 10 '18 at 20:32
  • See https://stackoverflow.com/a/45981809/3832970, there are solution for almost all languages. – Wiktor Stribiżew Aug 10 '18 at 20:37

0 Answers0