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. replace( QRegularExpression(".*"), "a:\folder\1-file"))
Forum Updated to NodeBB v4.3 + New Features

replace( QRegularExpression(".*"), "a:\folder\1-file"))

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 465 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
    StevenG
    wrote on last edited by
    #1

    Have this

    replace( QRegularExpression(".*"), "a:\folder\1-file"))
    

    So how to make '\1' to be just a regular text, and
    not a placeholder for the captured( 1) from
    QRE match group ?

    Any idea.

    JonBJ 1 Reply Last reply
    0
    • BondrusiekB Offline
      BondrusiekB Offline
      Bondrusiek
      wrote on last edited by
      #2

      I am not sure that it is what you want but try use double baskslashes to avoid captured by QRE.

      replace( QRegularExpression(".*"), "a:\\folder\\1-file") )
      
      1 Reply Last reply
      2
      • S StevenG

        Have this

        replace( QRegularExpression(".*"), "a:\folder\1-file"))
        

        So how to make '\1' to be just a regular text, and
        not a placeholder for the captured( 1) from
        QRE match group ?

        Any idea.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @StevenG
        Firstly, your literal string is wrong, this is just C++ 101. To even get something vaguely presentable you need

        replace( QRegularExpression(".*"), "a:\\folder\\1-file"))
        

        If you don't know the rules for protecting backslashes in C strings you should read up on them.

        Secondly it's not possible to give a correct answer to your question without knowing what the replace() method is. You choose to ask a question without even telling us that. There is no QRegularExpression::replace(), so who knows.

        not a placeholder for the captured( 1) from

        What capture? There is no capture/regular expressioning going on, at least not without know what replace() is....

        I will charitably assume you are talking about the replace() method of QString, https://doc.qt.io/qt-5/qstring.html#replace-12.

        I agree there is a problem: the docs state only

        For regular expressions containing capturing groups, occurrences of \1, \2, ..., in after are replaced with the string captured by the corresponding capturing group.

        without telling you how you can avoid that. However, they do state "For regular expressions containing capturing groups". Your reg exp, .*, does not contain any capturing groups, so hopefully this will simply not apply and \1 will be treated as literal. So, have you actually tried it (as corrected above) to see what happens?

        Furthermore, reg ex .* should match the whole string. In that case, won't it replace the whole string with a:\folder\1-file? And in that case, what's the point of doing any reg ex replace?!

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved