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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:26:56+00:00 2026-06-03T04:26:56+00:00

Given a string, how do I extract all sequences of exactly 4 digits? That

  • 0

Given a string, how do I extract all sequences of exactly 4 digits?

That is, for 1234 12 12345 1bc5 9876 I want to get [1234, 9876].

I got as far as re.findall('\D\d\d\d\d\D'), but that fails on text boundaries (when there’s no character before/after a match).


Solution preferably using Python 2.7, but I guess this is pretty general, any language will do.

  • 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-03T04:26:58+00:00Added an answer on June 3, 2026 at 4:26 am

    The general answer is surprisingly complicated, see here for more info. However in this particular case, we can simply use a word-boundary assertion \b:

    re.findall(r'\b\d{4}\b', ....)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a DataView that contains multiple rows, I want to extract a row based
I've been looking for a way to hash a given string in C# that
Algorithm to generate all possible letter combinations of given string down to 2 letters
What regular expression can I use (if any) to validate that a given string
I am designing a SQL query to extract all records from a given table.
Hi All I want to extract time for my local time zone which i
Given an XML fragment that I want to parse with XPath I first need
I have a string that contains some values I need to extract. Each of
I am trying to strip all the <br> 's in a given string. def
Following this question it gives me just 1st match. I want to get all

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.