Lukiya's Neverland

Are you the other side of the world to me...
Skip Navigation LinksHome - Post Archives - 2005 - 12 - 23 - 在Vs中使用正则表达式替换查找。

在Vs中使用正则表达式替换查找。

12/23/2005 04:43:00 PM - View : 200

今天终于把如何在vs中利用正则表达式进行查找替换摸到点门道,纪录下来以免忘记。

Xml文档如下

<? xmlversion="1.0"encoding="gb2312" ?>
< Topic >
?
< Issue >
???
< ID ></ ID >
???
< SortID ></ SortID >
???
< Title ></ Title >
???
< Author ></ Author >
???
< Editor ></ Editor >
???
< Source ></ Source >
???
< TopicPic ></ TopicPic >
???
< CreateTime ></ CreateTime >
???
< SortName ></ SortName >
???
< CommentCount ></ CommentCount >
???
< PageCount ></ PageCount >
???
< Content > <![CDATA[ {0} ]]> </ Content >
?
</ Issue >
</ Topic >

由于此xml文档是用来做模板的,所以想把每个元素innerText都替换成{$元素名$}的形式。

例如<SortID></SortID>替换成<SortID>{$SortID$}</SortID>的形式

手动太麻烦,就找资料想用正则表达式替换,结果真被我试出来了

操作如下:

1、Ctrl + F调出搜索框.

2、选中"Use"中的"Regular expresstions"

3、找那里填\<{.*}\>\<\/{.*}\>,替换那里填<\1\>\{\$\1\$\}\<\/\1\>

4、最后选替换全部搞定~~~举一反三,其他自己摸索去

Comments List
Poster Remember me next time.
Emotion 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
Content
Click to Refresh Validation Code.