Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9251073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:36:19+00:00 2026-06-18T10:36:19+00:00

I am trying to validate the input of a LineEdit widget in Qt. I

  • 0

I am trying to validate the input of a LineEdit widget in Qt. I am using regular expressions for the first time so I could use some help. I want to allow 1 to 32 hex bytes separated by a space, for example this should be valid:

"0a 45 bc 78 e2 34 71 af"

And here are some examples of invalid input:

"1 34 bc 4e" -> They need to be written in pairs, so 1 must be 01.

"8a cb3 58 11" -> cb3 invalid.

"56 f2 a8 69 " -> No trailing space is allowed.

After some head scratching I came up with this regex which seems to work:

"([0-9A-Fa-f]{2}[ ]){0,31}([0-9A-Fa-f]{2})"

Now on to my questions:

  1. Do you see any problems with my regex that my tests have failed to show? If so how can I improve it?

  2. Is there a cleaner way to write it?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:36:21+00:00Added an answer on June 18, 2026 at 10:36 am

    I am not sure what method you used for validation, but one possible problem is that the method searches the string for substring that matches the pattern rather than checking the string matches the pattern. Use exactMatch for validate a string against a regular expression.

    In any case, adding anchors ^ and $ is safer (not necessary when exactMatch is used, though):

    "^([0-9A-Fa-f]{2}[ ]){0,31}([0-9A-Fa-f]{2})$"
    

    Since you are doing validation, you don’t need capturing. And you don’t need to put space in []

    "^(?:[0-9A-Fa-f]{2} ){0,31}[0-9A-Fa-f]{2}$"
    

    You can set case-sensitivity with setCaseSensitivity method. If you set it to Qt::CaseInsensitive, you can shorten the regex a bit:

    "^(?:[0-9a-f]{2} ){0,31}[0-9a-f]{2}$"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to validate the input from the users with regular expressions here
I’m trying to validate input by using egrep and regex.Here is the line from
I'm trying to use a .NET Regex to validate the input format of a
I'm trying to use a RegularExpressionValidator to validate a TextBox input length. I have
I'm trying to create a registration form and validate input fields using javascript, but
I am trying to do some EditText validation and want to use an AlertDialog
I am trying to validate user input in WPF with Entlib 5.0. I want
I am trying to validate input date fields, and I want to make sure
I am trying to validate User Input in Windows Forms Application (using MVP design
I am trying to validate user input in a form instantly using jquery. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.