Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. can i give a string for in place of regExp in QML
QtWS25 Last Chance

can i give a string for in place of regExp in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qt5qmlregex
2 Posts 2 Posters 1.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.
  • V Offline
    V Offline
    vinaygopal
    wrote on 12 Oct 2021, 14:32 last edited by
    #1

    I tried doing something like this in QML and it wasnt allowed
    Item{
    property string reg_expression: "/[0-9]+/"
    ...
    ..
    .
    RegExpValidator {id:decimal_validator ; regExp: reg_expression}

    is there a way to give regExp in regExpValidator a string?
    because i want to send the regExp from the backend as a string to the QML side.

    Is this possible?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gojir4
      wrote on 12 Oct 2021, 14:53 last edited by Gojir4
      #2

      Guess you can give the string to RegExp constructor

      RegExpValidator {id:decimal_validator ; regExp: new RegExp(reg_expression)}
      

      Edit: Another point, I think you don't need to add extra "/" character if you define your regex using string.
      I think it should be either :

      property string reg_expression: "[0-9]+"
      

      or

      property RegExp reg_expression: /[0-9]+/
      

      Note also you can use "\\d+" or /\d/ instead of "[0-9]+" for your regex

      You may also be interested by this great website for developing and testing regex: https://regex101.com

      Edit2: Correction of my stupid mistake of my first edit. regex for digit character is obviously \d and not \w

      1 Reply Last reply
      1

      1/2

      12 Oct 2021, 14:32

      • 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