记事本++和正则表达式相当新,并且设法完成了我的大部分任务,但现在我被卡住了。
我有很多xml文件需要替换文本,但替换文本也在xml文件中。
有人知道怎么做吗?
请参阅附件屏幕截图,但代码如下:
<button name="Button2" height="39" width="124" left="211" top="422" visible="true" wallpaper="false" toolTipText="" exposeToVba="notExposed" isReferenceObject="false" style="3d" captureCursor="false" highlightOnFocus="true" tabIndex="1">
<command pressAction="" repeatAction="" releaseAction="abz" repeatRate="0.25"/><button
name="Button4" height="39" width="124" left="211" top="422" visible="true" wallpaper="false" toolTipText="" exposeToVba="notExposed" isReferenceObject="false" style="3d" captureCursor="false" highlightOnFocus="true" tabIndex="1">
<command pressAction="" repeatAction="" releaseAction=" abz" repeatRate="0.25"/>
Private Sub Button2_Released()
ScreenName = "test screen"
Private Sub Button4_Released()
ScreenName = "test screen info"
[enter image description here][1]
参见屏幕截图,我试图通过查找和替换功能将按钮表达式中的绿色突出显示文本替换为变量名称中的信息,其中蓝色和红色文本是匹配参数,绿色是替换位置和黄色是替代来源
答案 0 :(得分:0)
不确定按钮和命令节点之间是否有空格,但这样的东西就是你想要的。
查找
<button name="([^"]+)" height="39" width="124" left="211" top="422" visible="true" wallpaper="false" toolTipText="" exposeToVba="notExposed" isReferenceObject="false" style="3d" captureCursor="false" highlightOnFocus="true" tabIndex="1"><command pressAction="" repeatAction="" releaseAction="[^"]*"
替换:
<button name="$1" height="39" width="124" left="211" top="422" visible="true" wallpaper="false" toolTipText="" exposeToVba="notExposed" isReferenceObject="false" style="3d" captureCursor="false" highlightOnFocus="true" tabIndex="1"><command pressAction="" repeatAction="" releaseAction="$1"
它将使用第一个捕获组$ 1替换releaseaction值。 (按钮名称值)
答案 1 :(得分:0)
You could search and replace repeatedly this patterns:
Find: (<button name=")(.*?)(".*?releaseAction=").*?"(.*?Private Sub )\2(_Released.*?ScreenName = ")(.*?)(?=")
Replace: $1$2$3$6$4$2$5$6
With . matches newline
checked.
But I really do not recommend that.
Explanation:
The parts in parentheses are called "capture groups" and can be referred to in the search as well as in the replace expression.
(<button name=") group1 matches the part before the button name
(.*?) group2 matches the button name
(".*?releaseAction=") group3 matches the part between the button name
and the part to be replaced
.*? matches the part that will be replaced
(".*?Private Sub ) group4 matches the rest of the xml up to the next occurence
of the button name
\2 reference to group 2 (the button name)
(_Released.*?ScreenName = ") group5 matches the part up to the screen name
(.*?) group6 matches the screen name
(?=") non capturing look ahead, makes sure the capture group