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. QRegularExpressions not matching

QRegularExpressions not matching

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.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.
  • C Offline
    C Offline
    chabor
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    1
    • webzoidW Offline
      webzoidW Offline
      webzoid
      wrote on last edited by webzoid
      #2

      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'

      C 1 Reply Last reply
      1
      • webzoidW webzoid

        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'

        C Offline
        C Offline
        chabor
        wrote on last edited by chabor
        #3

        @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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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