Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Creator: How do I retain a regexp when replacing?
Qt 6.11 is out! See what's new in the release blog

Creator: How do I retain a regexp when replacing?

Scheduled Pinned Locked Moved Qt Creator and other tools
4 Posts 2 Posters 1.5k 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    I would like to replace instances like
    @obj.m_Member = "abc";@
    to something like
    @obj.setMember("abc");@

    However, replace does not quite do what I expect:
    I search using @obj.m_Member = "\w+";@ and get the results I want.
    However, when I replace with @obj.setMember("\w+");@, the \w+ is taken literally, not as the regexp result.

    Anything I can do, or is this feature simply missing?

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

      Hi,

      It's not missing. Without any pun you are getting what you are asking for.

      @obj.m_Member = ("\w+") <- capture what's between the parenthesis@

      @obj.Member(\1) <- use first captured text@

      Should to what you want

      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
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        Good to know. Why does it capture "what's between the parenthesis"? Parenthesis are so common in code it seems like a strange symbol to load with a special meta-meaning.

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

          That's defined by the regexp rules: a set of parenthesis captures what's in between but that's just it's simplest usage

          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