单词查找器正则表达式、PHP 和mysql
我有一个正在尝试针对单词数据库运行的查询。查询必须返回一个包含另一个单词和给定字母的单词。它是用 PHP 和 mySQL 编写的。
例如:
Word Given: Cruel
Letters Given: abcdty
在数据库中,我需要根据给定的字母和给定的单词找到“Cruelty”这个单词。它需要双向发挥作用。因此,如果我的字母为“atni”,那么如果数据库中存在“Anticruel”,就会出现“Anticruel”。
我已经工作了一半,但给出的结果不正确:
SELECT word
FROM words
WHERE LOCATE( "cruel", word ) >0
AND word != "cruel"
AND word
REGEXP '[ybilteh]'
此查询的结果集:
"anticruelty"
"crueler"
"cruelest"
"crueller"
"cruellest"
"cruelly"
"cruelness"
"cruelnesses"
"cruelties"
"cruelty"
更新!!!
感谢本杰明·莫雷尔(Benjamin Morel),我们离这个目标越来越近了。
此查询:
SELECT word
FROM words
WHERE LOCATE( "t", word ) >0
AND word != "t"
AND word
REGEXP '^[ybilteh]*t[ybilteh]*$'
LIMIT 0 , 30
正确查找单词。但也包括带有双字母的单词。如“甜菜”。当只有 1 个“e”可用时。
I have a query that I'm trying to run against a database of words. The query must return a word that contains another word, and letters given. It is in PHP and mySQL.
For example:
Word Given: Cruel
Letters Given: abcdty
In the database, I need to find the word "Cruelty" based on the letters given, and the word given. It needs to works both ways. So if I had "atni" for letters, "Anticruel" would appear if it existed in the database.
I have it half working but the result given is not correct:
SELECT word
FROM words
WHERE LOCATE( "cruel", word ) >0
AND word != "cruel"
AND word
REGEXP '[ybilteh]'
The result set from this query:
"anticruelty"
"crueler"
"cruelest"
"crueller"
"cruellest"
"cruelly"
"cruelness"
"cruelnesses"
"cruelties"
"cruelty"
Update!!!
Thanks to Benjamin Morel, this is getting much closer.
This query:
SELECT word
FROM words
WHERE LOCATE( "t", word ) >0
AND word != "t"
AND word
REGEXP '^[ybilteh]*t[ybilteh]*
Finds words correctly. But also includes words with double letters. Such as "Beet". When only 1 "e" is available.
LIMIT 0 , 30
Finds words correctly. But also includes words with double letters. Such as "Beet". When only 1 "e" is available.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
更新:让我们用 PHP 来优化,这个怎么样?
返回:残酷地,残酷地
你可能会找到更好/更简单的方法,但这应该可以解决问题!
Try this one:
UPDATE: let's go refining with PHP, what about this?
Returns: cruelly, cruelty
You might probably find a better/simpler approach, but that should do the trick!