MySql REGEXP Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • labmonkey111
    New Member
    • Sep 2008
    • 44

    MySql REGEXP Problem

    I've been using regular expressions for a few months, but I've hit a problem I can't figure out. I need a MySQL regexp to match a string made up of a sequence of characters occurring only 0 or 1 times. For example, for characters 'a', 'b', and 'c', I want to match to 'a', 'b', 'c', 'ab', 'ac', 'ba', 'bc', 'ca', 'cb', 'abc', 'acb', 'bac', 'bca', 'cab', 'cba', and nothing else.

    My problem is that I'm getting things like 'abcd' showing up because the 'abc' pattern is in there, but I want to match to an exact string, not a pattern existing somewhere in the string. I've gone thought dozens of different regular expressions and I can't get what I'm looking for. Any suggestions?
  • coolsti
    Contributor
    • Mar 2008
    • 310

    #2
    \b is a whole word break inidicater, meaning that

    Code:
    \babc\b
    should match abc which is not part of any string. You could maybe wrap the rest of your regexp expression in the \b tags.

    Comment

    Working...