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. Regular Expression for Multiple options.

Regular Expression for Multiple options.

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 4.3k 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.
  • A Offline
    A Offline
    Ayush Gupta
    wrote on 12 Aug 2019, 07:31 last edited by
    #1

    I have requiremen like below

    I need to write a regular expression for below match

    String should start with some charachters and end with digits

    something like
    ayush1 or gupta1

    I was trying like this

    ^\ayush|gupta[0-9]$

    But id did not helped.

    Basically my requirement to write a regular expression with multiple string options to be matched followed by some sequence of charachters.

    So in above case ayush1 should be matched and gupta1 should be matched. and we can give as many string like ayush , gupta for matching with OR option and it should followed by some sequence of charachters only which we will provide in regex.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 12 Aug 2019, 07:38 last edited by
      #2

      Hi
      You can use
      https://regexr.com/
      to practice.
      makes it easier to get it right.

      1 Reply Last reply
      2
      • A Offline
        A Offline
        Ayush Gupta
        wrote on 12 Aug 2019, 07:42 last edited by
        #3

        I tried but not reaching to my requirements :(

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Aug 2019, 08:04 last edited by
          #4

          Hi,

          One good site to test regular expression is regex101.com

          Based on your explanation it seems that ^\w+\d+?$ is what you are looking for.

          Note that Qt provides the QRegularExpression tool example that allows to test your regular expressions as well as get the string equivalent you need ot use in your code.

          For example, my suggestion becomes ^\\w+\\d+?$

          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
          3
          • V Offline
            V Offline
            VRonin
            wrote on 12 Aug 2019, 10:18 last edited by
            #5

            You need a non-capturing group: (?:ayush|gupta)[0-9]

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            A 1 Reply Last reply 12 Aug 2019, 10:59
            4
            • V VRonin
              12 Aug 2019, 10:18

              You need a non-capturing group: (?:ayush|gupta)[0-9]

              A Offline
              A Offline
              Ayush Gupta
              wrote on 12 Aug 2019, 10:59 last edited by
              #6

              @vronin Great Thanks

              1 Reply Last reply
              0

              4/6

              12 Aug 2019, 08:04

              • Login

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