0

I'm completely new about MySQL regexp and, after 3 days searching the web I've got to give up!

I need to find words into a database, exact words. But I need to take care about punctuation too (would be nice I provide my list of punctuation symbols). These words might be at the beginning of the database record, at the end or in the middle. They also can the the only data into the record. I don't care about uppercase or lowercase words.

Thus, I need to retrieve words in such cases:

Lion - Lion. - Lion, - Lion; - Lion... (dots) - Lion… (hellip) etc. (there can be many other punctuation symbols)

or

'Lion' - "Lion" - (Lion) - <Lion> - /Lion/ etc.

but those are incorrect:

Lion.tiger - Lions - superlion - <Lion" - (Lion> - Lion.....

I've tried dozens of regexp provided on several websites but none could solve that accurately.

Cheers.

4

1 回答 1

0

您应该能够使用单词边界。否则,您必须声明您愿意接受的所有字符。

select id,myRecord from my_records where myRecord REGEXP '[[:<:]]lion[[:>:]]';

这是一个SQL Fiddle,它使用了您为匹配而提供的一些示例。

请注意,由于.Lion.tiger 中的字符通常被认为是英语中的单词障碍(句末声明),因此您可能需要在不匹配它的情况下进行特殊情况。

select id,myRecord from my_records where
myRecord REGEXP '[[:<:]]lion[[:>:]]' and
myRecord NOT REGEXP '[[:<:]]lion\.[[:alpha:]]';

示例小提琴

于 2013-07-12T15:21:05.157 回答