我现在使用的就是TRegExp单元,
可就是不知道正则表达式Expression这个如何设置。
举个例子来说吧。
1、我有一个.doc文件;
2、将这个文件另存为.htm文件;
3、使用正则分析这个.htm文件,得到可显示的内容;
4、将这些可显示的内容替换为原内容+[一个随即数字];
5、将替换后的内容写回.htm文件;
6、打开.htm文件后看到,所有单个标记内容后都多了一个数字;
例:
原htm如下
<body lang=ZH-CN style='tab-interval:21.0pt;text-justify-trim
unctuation'>
<div class=Section1 style='layout-grid:15.6pt'>
<p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>张三</span></p>
<p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>李四</span></p>
<p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>王五</span></p>
<p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>孙六</span></p>
</div>
</body>
替换后如下:
<body lang=ZH-CN style='tab-interval:21.0pt;text-justify-trim
unctuation'>
<div class=Section1 style='layout-grid:15.6pt'>
<p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>张三123</span></p>
<p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>李四456</span></p>
<p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>王五789</span></p>
<p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>孙六000</span></p>
</div>
</body>