我想实现下面的,用伪mysql代码写的。Mysql REGEXP模式SELECT
数据库表(protected_paths.tbl
):
ID Path_Protected
1 /home/folder/private
2 /home/folder2/another-private
3 /home/folder3/subfolder/another/private-folder
4 /home/folder4/my_protected_folder
输入字符串:
Test | Match | String
1 | Y | /home/folder/private/another (caught by ID 1 above)
2 | Y | /home/folder/private/another/more (also caught by ID 1 above)
3 | N | /home/folder/work (not matched in table above)
4 | N | /home/folder/another-private (not matched in table above)
5 | N | /home/folder3/subfolder (not matched in table above - table above, ID 3, refers to deeper path)
都不行,很明显:
SELECT * FROM `protected_paths` WHERE Path_Protected = '/home/folder/private/another';
SELECT * FROM `protected_paths` WHERE Path_Protected REGEXP '/home/folder/private/another';
(我想这在匹配ID 1 protected_paths.tbl,因为它至少包含所有的字符串)
任何帮助将不胜感激。 干杯,达里尔
左侧''%是不是OP想我猜! –
@SabujHassan - 不确定... OP状态'至少包含所有包含左侧的字符串......通过任一方式获取点。谢谢! – sgeddes