用于替换 xml 属性的正则表达式 [英] regular expression to replace an xml attribute
问题描述
我有一个如下形式的 xml 文件:
<property name="foo" value="this is a long value">stuff</property>
有很多属性,但我想匹配名称为 foo 的属性,然后将其 value 属性替换为其他属性:
我正在考虑编写一个正则表达式来匹配foo"到标签末尾(>")之后的所有内容并替换它,但我似乎无法获得正确的语法.
如果有帮助的话,我正在尝试使用 sed 来执行此操作.
/property name=\"foo\" value=\"([^\"]*)\"/
>
然后只需将第一个子匹配替换为您希望的新值.
I have an xml file of the form:
<property name="foo" value="this is a long value">stuff</property>
There are many properties but I want to match the one with name foo and then replace its value attribute with something else as so:
<property name="foo" value="yet another long value">stuff</property>
I was thinking to write a regular expression to match everything after "foo" to the end of the tag ( ">" ) and replace that, but I can't seem to get the syntax right.
I'm trying to do this using sed, if that's any help.
/property name=\"foo\" value=\"([^\"]*)\"/
Then just replace the first submatch with the new value of your wishing.
这篇关于用于替换 xml 属性的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!