Answer the question
In order to leave comments, you need to log in
Powershell: how to replace by regexp in found by regexp?
There is an XML file with an approximate structure
<product> ...
<name> ....
<desc> HTML-код </desc>
<product> ...
<name> ....
<desc> только текст без тегов </desc>
[regex]::matches((Get-Content D:\test2.xml),"(?<=(<desc>)).*?(?=(</desc>))").value -replace '<[^>]*>', '' | sc d:\3.xml'
Answer the question
In order to leave comments, you need to log in
[regex]::replace(
(Get-Content D:\test2.xml),
'(?<=<desc>).*?(?=</desc>)',
{ $args[0].Value -replace '<[^>]*>', '' }
)
Alexey , the general wording is some kind of article on regexps, this has nothing to do with powershell. They are almost all olina now.
But even in the general case, if you iterate over only the found, it is not surprising that only the found is in the output.
then you need to move away from the onliner in one line and make a full-fledged cycle using the position of the found one in order to record the gaps too.
Or, (powershell only), for example, use and then clean in a cycle.
But converting to [xml], it seems to me, is easier -split '(<desc>.*?</desc>)'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question