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. Need help for QRegExp(unicode)
Forum Updated to NodeBB v4.3 + New Features

Need help for QRegExp(unicode)

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.0k 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.
  • S Offline
    S Offline
    stereomatching
    wrote on last edited by
    #1

    I want to parse the string by QString, but don't know how to deal with
    consecutive unicode

    @
    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForLocale(codec);
    QTextCodec::setCodecForCStrings(codec);

    QString const target = "<font color=\"#cc1105\" size=+1><b>氷菓  第18話「連峰は晴れているか」</b></font>";
    QRegExp exp("<font color=\"#cc1105\" size=\\+1><b>\\p{L}+</b></font>");   
    exp.indexIn(target);
    
    QTextEdit editor;
    editor.append(exp.cap(0));
    editor.append(exp.cap(1));
    editor.show();
    

    @

    "\p{L}" , "[.]+ " can't work either

    1 Reply Last reply
    0
    • S Offline
      S Offline
      scroverty
      wrote on last edited by
      #2

      If you just want to split the string and delete empty space, use "QString::split":http://qt-project.org/doc/qt-4.8/qstring.html#split.

      Note that the output give you a "QStringList":http://qt-project.org/doc/qt-4.8/qstringlist.html, which turn out to be just what you need to handle "consecutive" string.

      Alvis Ar'Berkeley Andrew.
      Pleased to meet you!

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stereomatching
        wrote on last edited by
        #3

        Thanks, but QString::split is not flexible enough for my requirement
        The doc say QRegExp support unicode, but I don't know
        how to manage unicode by QRegExp

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stereomatching
          wrote on last edited by
          #4

          @
          QString const target = "<font color="#cc1105" size=+1><b>氷菓 第18話「連峰は晴れているか」</b></font>";
          QRegExp exp("<font color="#cc1105" size=\+1><b>([^<]+)</b></font>");
          exp.indexIn(target);
          qDebug() << exp.cap(0) << endl << exp.cap(1);
          @

          I find out another solution, use ([^<]+) to catch the words
          QRegExp do not support "\p{L}" yet?

          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