[Solved] How to extract a Substring from a String using a Regular Exppression?



  • Hi all,

    I have the following text:

    DROP TRIGGER IF EXISTS Text1.Text1 or DROP TRIGGER IF EXISTS Text1

    And what I need it to extract the Text1 or the Text1.Text1 part using a Regular expression.

    Any idea?

    Best regards.





  • Hi,

    Here is how I resolved the problem:

    @

    QRegExp [removed]"^CREATE.(TABLE |TABLE IF NOT EXISTS |VIEW |DATABASE |PROCEDURE |FUNCTION |TRIGGER |EVENT ).[A-Za-z_\\d%]*\.{0,1}[A-Za-z_\\d%]*{0,1}");
    expression.indexIn(line);
    QRegExp expression2("[A-Za-z_\\d%]*\.[A-Za-z_\\d%]*");
    expression2.indexIn(line);
    symbolName = expression2.capturedTexts().at(0);
    if (symbolName.isEmpty()) {
    QRegExp expression3("[A-Za-z_\\d%]*");
    expression3.indexIn(line);
    symbolName = expression3.capturedTexts().at(0);
    }
    symbolName = symbolName.replace("`", "");
    symbolsLineNumber.insert(symbolName, counter);
    listSymbols->addItem(new QListWidgetItem(QIcon(icon), symbolName));
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.