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. Substring replacement and escape syntax
Forum Updated to NodeBB v4.3 + New Features

Substring replacement and escape syntax

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 988 Views 3 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.
  • V Offline
    V Offline
    voltron
    wrote on last edited by
    #1

    I need to replace some substring in the input string and in the same time support some sort of escape syntax. Here is an example of the input string

    http://myserver.com/share/$user/$locale
    

    here $user and $locale are substitution variables which should be replaced with corresponding values. In this case I can just use QString replace() method. Another example

    /media/$user/docs/$$version
    

    Here only $user is a substitution variable and should be replaced, $$version is escaped and should not be replaced.

    Number of the substitution variables in the input string is unknown, I only have list of possible variables, e.g. $user, $version, $locale, etc.

    How I can implement such functionality?

    K 1 Reply Last reply
    0
    • V voltron

      I need to replace some substring in the input string and in the same time support some sort of escape syntax. Here is an example of the input string

      http://myserver.com/share/$user/$locale
      

      here $user and $locale are substitution variables which should be replaced with corresponding values. In this case I can just use QString replace() method. Another example

      /media/$user/docs/$$version
      

      Here only $user is a substitution variable and should be replaced, $$version is escaped and should not be replaced.

      Number of the substitution variables in the input string is unknown, I only have list of possible variables, e.g. $user, $version, $locale, etc.

      How I can implement such functionality?

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @voltron

      The replace with regular expressions are good candidates for your purpose. Certainly it is also a complex way to do the job. The $ is a special character in QRegExp requiring escaping as well.

      Another way to do it step by step searching for $ in the strings.

      In case you like to go for the regular expressions and you have no experience there, I recommend to start with the QRegExp example. This is ideal to syntax check your expressions.

      The newer style would QRegularExpression with this example. Probably it does the same job as QRegExp.

      Vote the answer(s) that helped you to solve your issue(s)

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

        Hi,

        To add to @koahnig, go directly with QRegularExpression, QRegExp has been deprecated with Qt 5.

        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