Search code examples
regexregular-language

How to use regular expression to match just bracket?


Here, I want to use regular expression to replace all my code in Visual Studio like table.append(QString::fromLocal8Bit("test_code")); into just table.append("test_code");

So I think the rule should be first match "QString::fromLocal8Bit(",which should be QString::fromLocal8Bit\( in reg code. But I stuck at how to just skip some chars here until the first ")".

By the way, is there a regular expression website that could just output the regular pattern by inputting (several) pairs of original statements and the expected statements?


Solution

  • You need to capture the argument, or whatever that is (the "test_code") in a capturing group, and then replace the whole matched substring with that captured group:

    QString::fromLocal8Bit\((.*?)\)
    

    Replace with:

    $1
    

    (that is, replace with the first captured group)

    https://regex101.com/r/Muj7i6/1