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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:21:10+00:00 2026-06-07T15:21:10+00:00

>>> a = re.search(‘(\\d+h)?(\\d+m)?(\\d+s)?’, ‘in 1h15m’) >>> a.groups() (None, None, None) >>> a =

  • 0
>>> a = re.search('(\\d+h)?(\\d+m)?(\\d+s)?', 'in 1h15m')
>>> a.groups()
(None, None, None)
>>> a = re.search('.*(\\d+h)?(\\d+m)?(\\d+s)?', 'in 1h15m')
>>> a.groups()
(None, None, None)
>>> a = re.search('...(\\d+h)?(\\d+m)?(\\d+s)?', 'in 1h15m')
>>> a.groups()
('1h', '15m', None)

Why is the ‘…’ version the only one that populates ‘groups’?

  • 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-07T15:21:11+00:00Added an answer on June 7, 2026 at 3:21 pm

    Why are we getting empty groups?

    First one – a?a?a matched with "bbbaaa":

    • Start matching on the first position.
    • Try to match a, but can’t find. That’s Ok, it’s optional, so match nothing. (x 3 times)
    • Return a successful empty match, with no successful captured groups.

    Second one – .*a?a?a matched with "bbbaaa":

    • match .* from the first position to the last position.
    • Now we are at the end of the string.
    • Try to match a, but can’t find it. That’s Ok, it’s optional, so match nothing. (x 3 times)
    • Return a successful match with all original text, with no successful captured groups.

    How to solve this issue?

    It is unclear what exactly you are trying to do, but you can match for:

    \d+h(\d+m)?(\d+s)?|(\d+m)(\d+s)?|(\d+s)
    

    This assures you match at least one element – at least on option is not optional. Then, the regex would fail to match if none of the groups is available. You can parse it in a second step to get the groups, or use the group alternation feature (?| | ) if it is supported.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A search API is returning date in String format,I want to compare that date
Search logic is automagically doing an INNER JOIN on one the tables in my
i search for gridview user control opensource that allow me to set tabename then
I search for results, click one, it opens in a new window, then edit
.search .search_place li.search_button a { background: #017aa7; padding: 10px; color: #fff; text-decoration: none; font:
I search for a lot forums but nothing found, my problem is that I
I search grailsApplication.controllerClasses filter in stackoverflow,and I follow that right answer. I write codes
int search(int a[]) { int i,V,index; printf(Enter the element (V),That you want to find:>);
i search a tutorial or book a web that make an evidence a project
To search the database for rows that have both keywords foo AND bar in

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.