简体   繁体   中英

SQL query with regex in ms-access database

I'm working with C# .Net and ms-access database.

I have the following SQL query:

  `Select ... Like "%<aaa>%"+prmPhrase+"%</aaa>%"` 

The query is looking for a phrase inside a database field which contains xml data.

the query works very quickly, but it returns a lot of false results. I can't search only the exact phrase because i have a list of word boundry markers:

  ' ', '-', '.', ':', ',', ';', '/'

for example:

  prmPhrase = run  
  "i run home" -ok  
  "i.run-home" - ok  
  "running" - false result - not ok  

It takes me a lot of time to extract the ok results by code, and return only the ok sentences.

I would like to know if there is anything like regex or something which i could do a better query to return only the ok results without the false ones.

maybe this could help:

Search for "whole word match" in MySQL

Thanks For Advance!

Your task could be solved with something like "%" + SetA + "run" + SetB + "%"
where setA all symbols allowed before phrase (eg [az]*, to prevent end of tag, so % does not work), setB - all allowed delimiters (eg [^a-z0-9]).
I am afraid you could not define SetA with %, _, [] So you should simplify your task.

This doesn't help much in SQL, but Access can use the File System Object's RegExp support. Given the way your data is stored, that's likely not going to be much of a slowdown, since your LIKE matches wouldn't be using any indexes well anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM