Important: Please read the Qt Code of Conduct -

QRegExp and *literal* Minus/Dash

  • How do I match a literal Minus/Dash in QRegExp?

    My goal is to match a literal character, delimited by word boundaries.

    This works as expected, to match a literal x:
    @QRegExp test("\bx\b");@

    But neither of these works to match a literal "-" character:
    @QRegExp test1("\b-\b");
    QRegExp test2("\b(-)\b");
    QRegExp test3("\b\-\b");
    QRegExp test4("\b(\-)\b");@

    I think "-" shouldn't need escaping, but I tired with and without. No luck.

    How do I do it correctly?


Log in to reply