I have an MS Access DB along with a function (thanks @MPękalski) which is called by a query in the join
create table OSS_File(
id number,
Kw text(255));
insert into OSS_File(ID,kw) values(1,"black or white");
insert into OSS_File(ID,kw) values(2,"green");
insert into OSS_File(ID,kw) values(3,"blue berry");
insert into OSS_File(ID,kw) values(4,"blueberry");
insert into OSS_File(ID,kw) values(5,"bluegreen");
insert into OSS_File(ID,kw) values(6,"yellow");
create table restricted_words(
restricted_word text(255));
insert into restricted_words(restricted_word) values("\bblack\b");
insert into restricted_words(restricted_word) values("^green$");
insert into restricted_words(restricted_word) values("^blue[ ]?berry$");
insert into restricted_words(restricted_word) values("yellow");
Function my_regexp(ByRef sIn As String, ByVal mypattern As String) As String
Dim r As New RegExp
Dim colMatches As MatchCollection
With r
.Pattern = mypattern
.IgnoreCase = True
.Global = False
.MultiLine = False
Set colMatches = .Execute(sIn)
End With
If colMatches.Count > 0 Then
my_regexp = colMatches(0).Value
Else
my_regexp = ""
End If
End Function
SELECT restricted_words.restricted_word, OSS_File.ID, OSS_File.kw
FROM restricted_words INNER JOIN OSS_File
ON restricted_words.restricted_word=my_regexp(nz(OSS_File.kw),restricted_words.restricted_word);
I would have expected to get all but ID #5 back however I only get #6 back. If however I remove the ^,$, or \b I rewrite the function like
.Pattern = "^" & mypattern & "$"
or
.Pattern = "\b" & mypattern & "\b"
I can get back results (except for "blue[ ]?berry" due to the [ ]?).
Why when the entire regular expression is stored in the table does the mach fail?