文件1.wpl:
<?wpl version="1.0"?>
<smil>
<head>
<meta name="Generator" content="Microsoft Windows Media Player -- 12.0.22621.1"/>
<meta name="ItemCount" content="2"/>
<title>Untitled playlist</title>
</head>
<body>
<seq>
<media src="C:\Users\user\Downloads\Katzianerova vojna.mp3"/>
<media src="C:\Users\user\Downloads\Rat i mir u povijesti III- dio.mp3"/>
</seq>
</body>
</smil>
我想在多行中获取<seq>
和</seq>
之间的内容:
期望输出:
<media src="C:\Users\user\Downloads\Katzianerova vojna.mp3"/>
<media src="C:\Users\user\Downloads\Rat i mir u povijesti III- dio.mp3"/>
有这样的代码,它给我在单行输出:
$fileName = "C:\Users\user\Music\Playlists\1.wpl"
#Get content from file
$file = Get-Content $fileName
#Regex pattern to compare two strings
$pattern = "<seq>(.*?)</seq>"
#Perform the opperation
$results = [regex]::Match($file,$pattern).Groups[1].Value -split [System.Environment]::NewLine
return $results
实际产量:
<media src="C:\Users\user\Downloads\Katzianerova vojna.mp3"/> <media src="C:\Users\user\Downloads\Rat i mir u povijesti III- dio.m
p3"/>
3条答案
按热度按时间bvjxkvbb1#
当你拥有的是有效的XML时,没有理由使用正则表达式:
或者在XPath中使用通配符:
qgzx9mmu2#
你可以试着用一个“开关”
py49o6xq3#
发现溶液: