Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace a column using regex in ms access 2010

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?

like image 415
user1610952 Avatar asked Jan 01 '26 03:01

user1610952


1 Answers

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
like image 130
HansUp Avatar answered Jan 04 '26 00:01

HansUp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!