简体   繁体   English

如何使用正则表达式

[英]How to use regexp

I have 'tags' table with columns (id, link). 我有'tag'表和列(id,link)。 Link possible values: 链接可能的值:

id link
1  index
2  index/index
3  index/.*

when I got index, I need to select id 1. And: 当我得到索引时,我需要选择id 1.并且:

index -> 1
index/index -> 2
index/test -> 3

I use something like this: 我使用这样的东西:

SELECT * FROM tags WHERE 'index/test' REGEXP link LIMIT 1

But it's return me id 1, if I remove LIMIT second row will be id 3. I need just full math - only id 3. 但它返回我id 1,如果我删除LIMIT第二行将是id 3.我只需要完整的数学 - 只有id 3。

Also for regexp, the column identifier comes first, then the search value. 同样对于regexp,列标识符首先出现,然后是搜索值。 When I get you right, you want to get id -> 3 whenever the search term is not index or index/index. 当我找到你的时候,只要搜索项不是索引或索引/索引,你就想获得id - > 3。 So your regex could be something like 所以你的正则表达式可能是这样的

SELECT * FROM tags WHERE link REGEXP '[^index/index|^index]$'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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