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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:28:32+00:00 2026-06-04T20:28:32+00:00

I have the following text string and regex pattern in a c program: char

  • 0

I have the following text string and regex pattern in a c program:

char text[] = "        identification     division. "; 
char pattern[] = "^(.*)(identification *division)(.*)$"; 

Using regexec() library function, I got the following results:

String:         identification     division. 
Pattern: ^(.*)(identification *division)(.*)$ 
Total number of subexpressions: 3 

OK, pattern has matched  ... 

begin: 0, end: 37,match:         identification     division. 
subexpression 1 begin: 0, end: 8, match: 
subexpression 2 begin: 8, end: 35, match: identification     division 
subexpression 3 begin: 35, end: 37, match: . 

I was wondering since the regex engine matches in a greedy fashion and the first capture group (.*) matches any number of characters (except new line characters) why doesn’t it match characters all the way to the end in the text string (up to ‘.’) as oppose to matching only the first 8 spaces?

Does each capture group have to be matched?

Are there any rules on how the capture group matches the text string?

Thanks.

  • 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-04T20:28:33+00:00Added an answer on June 4, 2026 at 8:28 pm

    Just as you said, if the greedy group (.*) had consumed the whole string, the rest of the regex wouldn’t have anything to match which wouldn’t make your regex match the string. So, yes, each capture group (and other pattern parts) needs to be matched. This is exactly what you specified in your regex.

    Try the following string instead and run the code with both a reluctant and a greedy first group and you will see the difference.

    char text[] = "    identification  division    identification     division. ";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Python regex: xml_parse = re.search(r'^.+?<Hit_accession>(\w+?)</Hit_accession>.+?<Hsp_qseq>(\w+?)</Hsp_qseq>\s+?<Hsp_hseq>(\w+?)</Hsp_hseq>\s+?<Hsp_midline>(.+?)</Hsp_midline>',string,flags=re.DOTALL) for the following text: <?xml
I have the following regex that I have been using successfully: preg_match_all('/(\d+)\n(\w.*)\n(\d{3}\.\d{3}\.\d{2})\n(\d.*)\n(\d.*)/', $text, $matches)
I have the following table and would like to replace the string text of
Supposed I have the following string: string str = <tag>text</tag>; And I would like
I have the following text in xml file: <Config Builder=LP Wizard> <Libraries> <Library Name=XCAMSource/>
I have the following text: We%27re%20proud%20to%20introduce%20the%20Amazing I'd like to remove the encoding using PHP,
Let's say we have a string: somethinghere%C3somethinghere%83%C3%A8%C3%AF%C3%AD%C3%AEsomethinghere%C3%A7somethinghere What would be the Regex.Split pattern to
Let's suppose I have the following regex: -(\d+)- and I want to replace, using
I've created the following regex pattern in an attempt to match a string 6
I have the following method in some nemerle code: private static getLinks(text : string)

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.