douwei1904 2011-03-31 00:34
浏览 38
已采纳

简单正则表达式,用于检测以z开头但不是zz的字符串

I'm sorry if this sounds amateur (and for many of you this will) but I'm in a rush, and I thought I'd leverage the wonderful brains of this community rather than attempting to create and expression that does not work.

I need to achieve the following in MySQL!

In a certain field, if the string starts with a z, pick them up in teh SQL statement, but NOT if it's followed by another z. This only applies to the beginning (^) of the string. Case insensitive. So if the string is already "zz_fdfad" that should not be picked up, but anything with "zfda" should be picked up. Also, if the z is followed by anything other than an alpha numeric value, they should be NOT picked up (so I do NOT want results that are like "z_fdfdsa" or "z-fdfsdaa", or "z@fdfds".. you get the idea).

All this while keeping in mind I need an SQL statement for this in MySQL, and it will be processed in PHP.

Thank you so much!

  • 写回答

2条回答 默认 最新

  • dsztc99732 2011-03-31 00:41
    关注

    In SQL

    col Like 'z%' and not col like 'zz%'
    

    It's even index friendly!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计