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.2k 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.
  • Joel BodenmannJ Offline
    Joel BodenmannJ Offline
    Joel Bodenmann
    wrote on 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

    Joel BodenmannJ 1 Reply Last reply
    0
    • Joel BodenmannJ Joel Bodenmann

      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.

      Joel BodenmannJ Offline
      Joel BodenmannJ Offline
      Joel Bodenmann
      wrote on 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

      • Login

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