'Regex to extract specific XML tags and name them in XML file
I wanted to extract values and name the variables of two XML tags (FCF and DKY tags from the below sample). I was able to extract and name the values separately in two separate regex, but I am unable to read them together in one regex.
I am failing to get the output in one regex expression.
Sample XML:
<FCF>100</FCF>
<REF>AAAAAAAAAAAA</REF>
<DNA></DNA>
<DDB>1968-08-01 00:00:00</DDB>
<DKY>00003</DKY>
<DNT>ARE</DNT>
<DAD>1170</DAD>
<DCI>AE</DCI>
Current Powershell Script with regex:
switch -Regex -File $inputxml
{
'<FCF>(?<key1>[-]?\d+)</FCF>'
{
$currentFCF = $matches.Key1
continue
}
'<DKY>(?<key2>.*)</DKY>'
{
$currentDKY = $matches.Key2
continue
}
}
I am expecting to have something like this, but the below regex doesn't work
'<FCF>(?<Key1>[-]?\d+)</FCF>[\s\S]*<DKY>(?<Key2>.*)</DKY>'
{
$currentFCF = $matches.Key1
$currentDKY = $matches.Key2
continue
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
