开发者

regular expression for starting character sequence mysql 5.1

I require a regular expression that selects a column from table, if it starts with a specific character sequence specified by the user.

example if i type in A i should get

Apple Apricot Acorn

if i type in A开发者_开发问答b

Abba Abdomen

etc..

This is for a query done in mysql 5.1

Thanks,


Don't use regex for this, use LIKE:

SELECT * from my_table WHERE name LIKE 'A%'


SELECT ... WHERE fieldname REGEXP '^Ab';

details here. But if you're doing purely "start of string" matching, then use .. LIKE 'Ab%', which is somewhat more efficient and can use indexes. If you need to search for any field which has a word anywhere in it that starts with Ab, then by all means use regexes: REGEXP '[[:<:]Ab'


The regex portion of it would be:

'^yourCharacterSequenceHere'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜