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

  • SEARCH
  • Home
  • 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 8579389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:36:00+00:00 2026-06-11T20:36:00+00:00

My file contains either 45 hex numbers, separated by whitespaces or 48 hex numbers,

  • 0

My file contains either 45 hex numbers, separated by whitespaces or 48 hex numbers, separated by whitespaces. I need ALL of those numbers individually and not as a whole. I am currently using a brute force method to get 45 numbers.

pattern = re.compile("([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s")

However, even with this, I still cant figure out how to extract the remaining three numbers in a 48 hex number instance. Could you please help me out with simplifying this problem?

I would avoid solutions like the ones below (haven’t tried if it works) as I will have to later split the string for each instance i.e. considering it gives proper output!

(((?:[0-9a-f]{2})\s){48})|(((?:[0-9a-f]{2})\s){45})

Thank you!

  • 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-11T20:36:01+00:00Added an answer on June 11, 2026 at 8:36 pm

    When writing long REs, consider using re.VERBOSE to make them more readable.

    pattern = re.compile(r"""
     ^( [0-9a-fA-F]{2} (?: \s [0-9a-fA-F]{2} ){44}
                    (?:(?: \s [0-9a-fA-F]{2} ){3} )? )$ 
    """, re.VERBOSE)
    

    Read as: two hex digits, followed by 44 times (space followed by two hex digits), optionally followed by 3 times (space followed by two hex digits).

    Test:

    >>> pattern.match(" ".join(["0f"] * 44))
    >>> pattern.match(" ".join(["0f"] * 45))
    <_sre.SRE_Match object at 0x7fd8f27e0738>
    >>> pattern.match(" ".join(["0f"] * 46))
    >>> pattern.match(" ".join(["0f"] * 47))
    >>> pattern.match(" ".join(["0f"] * 48))
    <_sre.SRE_Match object at 0x7fd8f27e0990>
    >>> pattern.match(" ".join(["0f"] * 49))
    

    Then finally, to retrieve the individual digits, do .group(0).split() on the match result. That’s much easier than writing an RE that puts all the digits into separate groups.

    EDIT: alright, here’s how to solve the original problem. Just construct the RE dynamically.

    chunk = r"""([0-9a-fA-F]{2}\s)"""
    pattern = re.compile(chunk * 45 + "(?:" + chunk * 3 + ")?")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The below file contains all the javascript for a page. Performance is the highest
I am creating a master database using SQLite. This single file contains a dozen
I have a text file which contains columns of data that are either integer,
I have a UTF-8 formatted data file that contains thousands of floating point numbers.
I am using delphi 7 and need to uncompress a compressed zip file which
I'm trying to read all lines of a file that are either all upper
Suppose I have a text file where each line contains either '1' or '-1.'
I need to verify that the text of a file contains text in the
Each file contains 3D points which I want to display. I want to see
tmp-file contains: database_1 database_2 database_3 I want to run a command like mysqldump DATABASE

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.