Home  >  Q&A  >  body text

java - mysql的查询正则表达式怎么写?

mysql现在有一个字段code,我现在需要的规则是,前一位(或两位)我提供了固定值,java后台生成的,比如I或IC。然后后四位随意,然后后两位后面的4位java后台也会生成,也是固定的,最后末尾还有三位随意。比如I17 04 0000 000或IC17 04 0000 000

难么mysql的select语句怎么写,求大神告知。。。。
PS.1位(两位)固定,四位随意,四位固定,三位随意
select code from xxxx where??

PHP中文网PHP中文网2742 days ago552

reply all(4)I'll reply

  • 大家讲道理

    大家讲道理2017-04-18 10:58:41

    SELECT code FROM xxxx WHERE code REGEXP '^(I|IC)[0-9]{4}0000[0-9]{3}$';
    

    or

    SELECT code FROM xxxx WHERE code LIKE 'I____0000%' OR code LIKE 'IC____0000___';

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 10:58:41

    where code REGEXP is followed by a regular expression

    reply
    0
  • 阿神

    阿神2017-04-18 10:58:41

    In addition to using like, can other methods be used for fuzzy search in MySQL?

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:58:41

    Use like, mysql does not have regular expressions, so there is no need to use regular expressions for your needs.

    reply
    0
  • Cancelreply