简体   繁体   中英

MYSQL Advanced Wild Card Search

Say my mysql table has a field name with a value of record 1: Steve ABCDEF data record 2: Steve C data record 3: Steve BCF data record 4: Steve FC data

I want to search for results that contain something like "Steve %C% " Which would bring up record 1 2 & 3 I don't however, want it to pull up record 4!

Because I only want the wild card to go to the space character. Once it hits space, I want it to stop searching.

So something like:

SELECT * FROM `test` WHERE `name` REGEXP 'Steve \*[C]\*'

This obviously doesn't work though, because it will bring up all the records (including record 4), and I only want it if it has the "C" before the space, ie. records 1, 2, & 3.

Is this even possible?

您可以尝试以下方法:

SELECT * FROM `test` WHERE `name` REGEXP 'Steve [^[:space:]]*C'

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