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. Converting search string to QRegularExpression pattern
Forum Updated to NodeBB v4.3 + New Features

Converting search string to QRegularExpression pattern

Scheduled Pinned Locked Moved Solved General and Desktop
qregularexpresssearch
2 Posts 1 Posters 1.1k Views 2 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.
  • J Offline
    J Offline
    Joel Bodenmann
    wrote on 31 Jul 2016, 10:30 last edited by Joel Bodenmann
    #1

    I have a widget that has API to set a QRegularExpression that will be used to highlight certain contents of the widget. The user is able to enter a regular expression in a QLineEdit and everything works quite well. I'd now like to give the user the ability to toggle between "regex mode" and "plain string compare" mode as some users might not know regex and others are annoyed to escape all the characters if they are looking for something with special symbols.

    My question: Is there any way I can convert the "plain string" to a valid QRegularExpression? I'd like to avoid modifying said widget to offer search & highlight capabilities by just doing good old QString::compare(). I looked through the docs but it seems that QRegularExpression doesn't offer such a feature and it's not enough that I just escape any non-alphanumeric character.

    I'd be thankful for any kind of help & advice.

    Industrial process automation software: https://simulton.com
    Embedded Graphics & GUI library: https://ugfx.io

    J 1 Reply Last reply 31 Jul 2016, 11:45
    0
    • J Joel Bodenmann
      31 Jul 2016, 10:30

      I have a widget that has API to set a QRegularExpression that will be used to highlight certain contents of the widget. The user is able to enter a regular expression in a QLineEdit and everything works quite well. I'd now like to give the user the ability to toggle between "regex mode" and "plain string compare" mode as some users might not know regex and others are annoyed to escape all the characters if they are looking for something with special symbols.

      My question: Is there any way I can convert the "plain string" to a valid QRegularExpression? I'd like to avoid modifying said widget to offer search & highlight capabilities by just doing good old QString::compare(). I looked through the docs but it seems that QRegularExpression doesn't offer such a feature and it's not enough that I just escape any non-alphanumeric character.

      I'd be thankful for any kind of help & advice.

      J Offline
      J Offline
      Joel Bodenmann
      wrote on 31 Jul 2016, 11:45 last edited by
      #2

      Never mind. QRegularExpression::escape() does exactly what I want.

      Industrial process automation software: https://simulton.com
      Embedded Graphics & GUI library: https://ugfx.io

      1 Reply Last reply
      1

      1/2

      31 Jul 2016, 10:30

      • Login

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