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 8194899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:57:47+00:00 2026-06-07T04:57:47+00:00

I want to make sure using regex that a string is of the format-

  • 0

I want to make sure using regex that a string is of the format- “999.999-A9-Won” and without any white spaces or tabs or newline characters.

  1. There may be 2 or 3 numbers in the range 0 – 9.
  2. Followed by a period ‘.’
  3. Again followed by 2 or 3 numbers in the range 0 – 9
  4. Followed by a hyphen, character ‘A’ and a number between 0 – 9 .
  5. This can be followed by anything.

Example: 87.98-A8-abcdef

The code I have come up until now is:

testString = "87.98-A1-help"
regCompiled = re.compile('^[0-9][0-9][.][0-9][0-9][-A][0-9][-]*');
checkMatch = re.match(regCompiled, testString);
if checkMatch:
    print ("FOUND")
else:
    print("Not Found")

This doesn’t seem to work. I’m not sure what I’m missing and also the problem here is I’m not checking for white spaces, tabs and new line characters and also hard-coded the number for integers before and after decimal.

  • 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-07T04:57:48+00:00Added an answer on June 7, 2026 at 4:57 am

    With {m,n} you can specify the number of times a pattern can repeat, and the \d character class matches all digits. The \S character class matches anything that is not whitespace. Using these your regular expression can be simplified to:

    re.compile(r'\d{2,3}\.\d{2,3}-A\d-\S*\Z')
    

    Note also the \Z anchor, making the \S* expression match all the way to the end of the string. No whitespace (newlines, tabs, etc.) are allowed here. If you combine this with the .match() method you assure that all characters in your tested string conform to the pattern, nothing more, nothing less. See search() vs. match() for more information on .match().

    A small demonstration:

    >>> import re
    >>> pattern = re.compile(r'\d{2,3}\.\d{2,3}-A\d-\S*\Z')
    >>> pattern.match('87.98-A1-help')
    <_sre.SRE_Match object at 0x1026905e0>
    >>> pattern.match('123.45-A6-no whitespace allowed')
    >>> pattern.match('123.45-A6-everything_else_is_allowed')
    <_sre.SRE_Match object at 0x1026905e0>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using APEX 3.2 and I want to make sure that a text
I want to make sure that if any error occurs during the database processing
I want to make sure that the user does not input any of these
I've created some business classes using OO Perl and I want to make sure
I want to make sure a string has only characters in this range [a-z]
I'm using several images to style UITableViewCells and I want to make sure I'm
I have a string and I want to make sure it only contains characters
I want to make sure that the strings I save to the database are
I want to make sure that a set of functions have the same signature
I want to make sure a CGSize is smaller or equal to another CGSize

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.