Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QRegularExpression with a character class behaving strangely
Qt 6.11 is out! See what's new in the release blog

QRegularExpression with a character class behaving strangely

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 576 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GraemeA
    wrote on last edited by
    #1

    I'm trying to use QRegularExpression to extract Arabic text (0x600-0x6ff) from a string. Below is the sample code and output. (I've included duplicate code that picks out latin lowercase letter just to convince myself that the method should work.)
    @
    QRegularExpressionMatchIterator iter;
    QRegularExpression regex("([\x61-\x7a]+)");
    qDebug() << "lower case QRegularExpression pattern" << regex.pattern() << regex.isValid();

    iter = regex.globalMatch("the cow JUMPED over");
    while(iter.hasNext()) {
    QRegularExpressionMatch match = iter.next();
    if (match.isValid()) {
    qDebug() << match.capturedTexts();
    }
    }
    QRegularExpression arabic("([\x600-\x6ff]+)");;
    qDebug() << "arabic regex" << arabic.pattern() << arabic.isValid();
    iter = arabic.globalMatch("You say, كَتَبَ إِلَىَّ يَسْتَبْطِئُنِى He wrote ");
    while(iter.hasNext()) {
    QRegularExpressionMatch match = iter.next();
    if (match.isValid()) {
    qDebug() << match.capturedTexts();
    }
    }
    @

    Produces this:
    @
    lower case QRegularExpression pattern "([\x61-\x7a]+)" true
    ("the", "the")
    ("cow", "cow")
    ("over", "over")
    arabic regex "([\x600-\x6ff]+)" true
    ("Yo", "Yo")
    ("a", "a")
    ("He", "He")
    ("o", "o")
    ("e", "e")
    @

    I think it might be a clue that if I specify the lowercase regex pattern as ([\x061-\x07a]+) it considers it to be invalid.

    By the way, QRegExp with the arabic pattern works Ok.

    Any ideas how to specify character classes correctly?

    Thanks.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved