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. Find a complex substring in another string
QtWS25 Last Chance

Find a complex substring in another string

Scheduled Pinned Locked Moved General and Desktop
findsubstringstring
5 Posts 2 Posters 2.9k Views
  • 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.
  • M Offline
    M Offline
    MohammadReza
    wrote on last edited by
    #1

    Hi everybody,
    I have a substring for example:
    43ab??12??56??ef
    ?? are wildcard and the count of ?? is unknown.
    I want to check the main string contains this substring or not.
    The substring is not unique and it changes always.

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      You want to use Regular Expressions. Use this as your pattern: 43ab.*12.*56.*ef

      • http://regexone.com/
      • http://doc.qt.io/qt-5/qregularexpression.html

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      M 1 Reply Last reply
      0
      • JKSHJ JKSH

        Hi,

        You want to use Regular Expressions. Use this as your pattern: 43ab.*12.*56.*ef

        • http://regexone.com/
        • http://doc.qt.io/qt-5/qregularexpression.html
        M Offline
        M Offline
        MohammadReza
        wrote on last edited by
        #3

        @JKSH Hi dear JKSH. Thanks for your reply.
        I know but my substring is unpredictable and I can not use a constant regular expression.
        For example:
        32??
        or
        ??ae8298
        or
        ??????34????
        or
        5798a3??12??dbfe4a93??b2
        or ...

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @MohammadReza said:

          @JKSH Hi dear JKSH. Thanks for your reply.
          I know but my substring is unpredictable and I can not use a constant regular expression.

          Well, what are the characteristics that are common to all of your substrings? You need to identify this information first, before you can design your search logic.

          How are these substrings generated? What are they used for? What other things do your "main string" contain?

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MohammadReza
            wrote on last edited by MohammadReza
            #5

            @JKSH Thanks.
            By using of RegExp, the problem is solved.
            For other users who read this question:
            My main string is a string of hex (without any space or \x or 0x). I replcae ? in substring by [0-9a-f] and use Qt::CaseInsensitive option:

            regex.replace("?","[0-9a-f]");
            index = mainString.indexOf(QRegExp(regex,Qt::CaseInsensitive));
            
            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