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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:21:21+00:00 2026-05-15T20:21:21+00:00

This may be a silly question but… Say you have a sentence like: The

  • 0

This may be a silly question but…

Say you have a sentence like:

The quick brown fox

Or you might get a sentence like:

The quick brown fox jumped over the lazy dog

The simple regexp (\w*) finds the first word “The” and puts it in a group.

For the first sentence, you could write (\w*)\s*(\w*)\s*(\w*)\s*(\w*)\s* to put each word in its own group, but that assumes you know the number of words in the sentence.

Is it possible to write a regular expression that puts each word in any arbitrary sentence into its own group? It would be nice if you could do something like (?:(\w*)\s*)* to have it group each instance of (\w*), but that doesn’t work.

I am doing this in Python, and my use case is obviously a little more complex than “The quick brown fox”, so it would be nifty if Regex could do this in one line, but if that’s not possible then I assume the next best solution is to loop over all the matches using re.findall() or something similar.

Thanks for any insight you may have.

Edit: For completeness’s sake here’s my actual use case and how I solved it using your help. Thanks again.

>>> s = '1 0 5 test1 5 test2 5 test3 5 test4 5 test5'
>>> s = re.match(r'^\d+\s\d+\s?(.*)', s).group(1)
>>> print s
5 test1 5 test2 5 test3 5 test4 5 test5
>>> list = re.findall(r'\d+\s(\w+)', s)
>>> print list
['test1', 'test2', 'test3', 'test4', 'test5']
  • 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-05-15T20:21:22+00:00Added an answer on May 15, 2026 at 8:21 pm

    I don’t believe that it is possible. Regexes pair the captures with the parentheses in the given regular expression… if you only listed one group, like ‘((\w+)\s+){0,99}’, then it would just repeatedly capture to the same first and second group… not create new groups for each match found.

    You could use split, but that only splits on one character value, not a class of characters like whitespace.

    Instead, you can use re.split, which can split on a regular expression, and give it ‘\s’ to match any whitespace. You probably want it to match ‘\s+’ to gather the whitespace greedily.

    >>> import re
    >>> help(re.split)
    Help on function split in module re:
    
    split(pattern, string, maxsplit=0)
        Split the source string by the occurrences of the pattern,
        returning a list containing the resulting substrings.
    
    >>> re.split('\s+', 'The   quick brown\t fox')
    ['The', 'quick', 'brown', 'fox']
    >>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a silly question but... Say I have a String like 4e59
This may be a silly question, but say I want to get two values
This may seem like a silly question but I can't figure it out. let's
This may be a silly question, but right now I have a rather large
Now this may seem like a silly question, but I need to know how
This may be a silly question (but I'm new to multicast). I have a
This may sound like a silly question but in D (using std.regex ) how
This may seem like a silly question but I can't find anything to help.
Im new to rails so this may seem like a silly question but why
This may seem like a silly question, but I thought I'd ask it anyway

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.