在ms Access 2010中使用正则表达式替换列 [英] replace a column using regex in ms access 2010

查看:77
本文介绍了在ms Access 2010中使用正则表达式替换列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ms Access 2010中有一个名为sample的表,仅包含一列,正文(类型:文本):

There's a table named sample including only one column, body (type: text) in ms access 2010:

<name>John</name><age>12</age>

我想删除方括号内的每个字符串.看到这个:

I'd like to delete every string inside the brackets. See this:

John12

我添加了Microsoft VBScript正则表达式5.5库并创建了此模块:

I added Microsoft VBScript Regular Expression 5.5 library and create this module:

Function Replace_Regex(str1, patrn, replStr)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True

Replace_Regex = regEx.Replace(str1, replStr)
End Function

然后,我运行以下查询: 更新样本 set body = Replace_Regex(body,< [^>] +?",")

And then, I run this query: update sample set body = Replace_Regex(body, "<[^>]+?", "")

但是结果是:

 ame>John</name><age>12</age>

那有什么问题?

推荐答案

将此添加到函数中:

regEx.Global = True

然后使用"<[^>]*>"作为模式.

这是我在即时"窗口中看到的内容:

Here's what I get in the Immediate window:

body = "<name>John</name><age>12</age>"
? Replace_Regex(body, "<[^>]*>", "")
John12

这篇关于在ms Access 2010中使用正则表达式替换列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆