简体   繁体   中英

Mysql REGEXP exact match

I'm trying to match on ONLY the word "arcfour" and not arcfour128 or arcfour256. What would be the correct regex line?

select * from TABLE where COLUMN REGEXP ==>  arcfour  <===;

What regexp syntax do I need to ONLY look for arcfour?

Example listing in COLUMN:

arcfour
arcfour128
arcfour256

You can use ^ to select the start of a string, and $ to select the end . This means that everything inside ^ and $ will be the only data that can exist. It must be on its own, not surrounded by any extra characters or symbols.

For example, ^data$ will only match if the string if data . Any numbers of letter, before or after it will cause the string to not match. Therefore 1data and data2 will not match.

In your case, you should use the following Code and RegEx:

select * from TABLE where COLUMN REGEXP '^arcfour$'

Live Demo on RegExr


Note that if you want the table data to match only one specific string, it makes sense to not use RegEx, but use = , like so:

select * from TABLE where COLUMN = 'arcfour'

如果您想要完全匹配,则不应该首先使用正则表达式,而只需进行相等匹配即可。

SELECT * FROM table WHERE column = 'arcfour'

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