Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QRegularExpressions not matching



  • Hello,
    I'm trying to use QRegularExpressinos to match any URL in a larger string.
    My regex is:

    \b(https?|ftp|file)(:\/\/)([-A-Z0-9+&@#\/%?=~_|!:,.;]*[A-Z0-9+&@#\/%=~_|])(\.[-A-Z0-9]*)
    

    Testing it out on sites like regex101 works, but in Qt it won't match.
    I'm also using the same options i.e. /i /g.
    Do i have to format it differently?

    Thanks.



  • I've only done a little bit of work with regular expressions in Qt. Just checking, you've used escape characters within your expression? Like '\\b' instead of '\b'



  • @webzoid Yep I'm pretty sure I escaped everything I need to, like the double-slash and literal dots.
    Edit: Oh god I forgot to escape my "\b" at the beginning. You're right, thank you.
    But for some reason regex101 didn't care. Whelp.


  • Lifetime Qt Champion

    Hi,

    You can use the regular expression example tool to check your regexp as well as get the escaped version for your code.


Log in to reply