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. [SOLVED]Regular Exp help
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Regular Exp help

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.3k 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.
  • G Offline
    G Offline
    GrahamL
    wrote on last edited by
    #1

    Hi
    I am new to regular expressions and would appreciate some help.
    I need to match the the string "TestUI_xx.txt", where 'xx' mut be 2 alphabetical characters, but cannot see how to do this.

    I would be grateful if someone could point me in the right direction

    Thanks

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

      Hi,

      the "QRegExp":http://qt-project.org/doc/qt-4.8/qregexp.html documentation contains all you need for that.

      Here's what you basically need:
      @TestUI_[a-z]{2}.txt@

      There also the very useful Regular Expression Example that you can build to test/validate your regexp.

      If you're using Qt 5 there's also the QRegularExpression class

      Hope it helps

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

        Thanks very much - works like a charm

        1 Reply Last reply
        0
        • TheBadgerT Offline
          TheBadgerT Offline
          TheBadger
          wrote on last edited by
          #4

          Hi,

          To point you in the right direction, read the documentation on Regular Expressions in Qt:

          • QRegExp in "Qt 4.8":https://qt-project.org/doc/qt-4.8/QRegExp.html or "Qt 5.0":http://qt-project.org/doc/qt-5.0/qtcore/qregexp.html
          • QRegularExpression in "Qt 5.0":http://qt-project.org/doc/qt-5.0/qtcore/qregularexpression.html

          For Qt 5 I think QRegularExpression is preferred, see "this":https://qt-project.org/wiki/Regexp_engine_in_Qt5 link.

          I did use the documentation on 4.8 to learn the basics of Regular Expressions so that would be a good starting point. I still refer back to that page when doing RexExps.

          If you understand Regular Expressions and patterns, you can use the "Regular Expression" example application in Qt Creator to test a pattern before you implement it in an application.

          To give you the answer:
          The pattern you need should be something like:
          @
          QString pattern("^TestUI_[a-zA-z]{2}.txt$");
          @

          What should the output be of your match?


          Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

          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