mysql - Match specified integers -
i have following regex:
1|2|3|4|5|6
it's sql part, , want match 6 ids. problem regex matches integers 11, 12, 13, 14, 15, 16, 23, etc.
how can form regex match 6 specific integers?
in order use "shorter" queries, can use alternation character class regexp
:
select * table id regexp '^([1-6]|23)$'
the character class [1-6]
matches numbers 1
6
, , |
used list other alternatives. grouping (...)
makes anchors ^
(beginning of string) , $
(end of string) apply possible alternatives.
if ids passed separately , regex created dynamically, use alternation:
^(23|6|5|4|3|2|1)$
however, if have small subset of ids, you'd better use or
syntax list alternatives since non-regex solutions less resource-consuming.
Comments
Post a Comment