replace a column using regex in ms access 2010

房东的猫 提交于 2019-12-02 02:49:22

问题


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

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

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

But the result is:

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

So, what's the problem?


回答1:


Add this to the function:

regEx.Global = True

Then use "<[^>]*>" as the pattern.

Here's what I get in the Immediate window:

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


来源:https://stackoverflow.com/questions/12188796/replace-a-column-using-regex-in-ms-access-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!