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. How to restore a regex rule into the json file?
Forum Updated to NodeBB v4.3 + New Features

How to restore a regex rule into the json file?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 312 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.
  • nicker playerN Offline
    nicker playerN Offline
    nicker player
    wrote on last edited by
    #1

    When I put the text into the file and used the QJsonObject to parse the data,u know it couldnt work.I knew it maybe was caused by the spcial code what likes the ^$ and so on .But how to fix it ?

    {
    "context_utils_string_regex_rules":{
    		"rule_mail_addr_default":"^[A-Za-z0-9-._]+@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,6})$",
    		"rule_mail_addr_server":"@[A-Za-z0-9-]+(\.)",
    		"rule_mail_addr_username":"^[A-Za-z0-9-]*@"
    }
    }
    
    JonBJ 1 Reply Last reply
    0
    • nicker playerN nicker player

      When I put the text into the file and used the QJsonObject to parse the data,u know it couldnt work.I knew it maybe was caused by the spcial code what likes the ^$ and so on .But how to fix it ?

      {
      "context_utils_string_regex_rules":{
      		"rule_mail_addr_default":"^[A-Za-z0-9-._]+@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,6})$",
      		"rule_mail_addr_server":"@[A-Za-z0-9-]+(\.)",
      		"rule_mail_addr_username":"^[A-Za-z0-9-]*@"
      }
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @nicker-player
      What "does not work"? JSON knows nothing about regular expressions, it only accepts strings. So long as your strings are well formed it will parse them; what you do with them later is a completely separate matter.

      So what is the problem here? Does the file read into JSON without error, or does it give you a line and error? I haven't looked it up, but maybe JSON requires something for your literal \s? [EDIT Yep, JSON requires \\ for a literal \.]

      C 1 Reply Last reply
      1
      • JonBJ JonB

        @nicker-player
        What "does not work"? JSON knows nothing about regular expressions, it only accepts strings. So long as your strings are well formed it will parse them; what you do with them later is a completely separate matter.

        So what is the problem here? Does the file read into JSON without error, or does it give you a line and error? I haven't looked it up, but maybe JSON requires something for your literal \s? [EDIT Yep, JSON requires \\ for a literal \.]

        C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        You would need to escape literal double-quotes if they are also present within the regular expressions. Using a JSON package/library, like QJSonDocument, to write the file is the easiest way to ensure that escaping happens where it should (and is reversed on read).

        Another observation: your email address regex is not allowing for a lot of options. This, for example, is a valid email address, "someone+something@example.com". See this Stackoverflow article for more.

        1 Reply Last reply
        2

        • Login

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