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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:35:46+00:00 2026-05-12T14:35:46+00:00

On my OS X 10.5.8 machine, using the regcomp and regexec C functions to

  • 0

On my OS X 10.5.8 machine, using the regcomp and regexec C functions to match the extended regex “(()|abc)xyz”, I find a match for the string “abcxyz” but only from offset 3 to offset 6. My expectation was that the entire string would be matched and that I would see a submatch for the initial “abc” part of the string.

When I try the same pattern and text with awk on the same machine, it shows a match for the entire string as I would expect.

I expect that my limited experience with regular expressions may be the problem. Can somebody explain what is going on? Is my regular expression valid? If so, why doesn’t it match the entire string?

I understand that “((abc){0,1})xyz” could be used as an alternative, but the pattern of interest is being automatically generated from another pattern format and eliminating instances of “()” is extra work I’d like to avoid if possible.

For reference, the flags I’m passing to regcomp consist only of REG_EXTENDED. I pass an empty set of flags (0) to regexec.

  • 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-12T14:35:46+00:00Added an answer on May 12, 2026 at 2:35 pm

    The POSIX standard says:

    9.4.3 ERE Special Characters

    An ERE special character has special properties in certain contexts. Outside those contexts, or when preceded by a <backslash>, such a character shall be an ERE that matches the special character itself. The extended regular expression special characters and the contexts in which they shall have their special meaning are as follows:

    .[\(

    The <period>, <left-square-bracket>, <backslash>, and <left-parenthesis> shall be special except when used in a bracket expression (see RE Bracket Expression ). Outside a bracket expression, a <left-parenthesis> immediately followed by a <right-parenthesis> produces undefined results.

    What you are seeing is the result of invoking undefined behaviour – anything goes.

    If you want reliable, portable results, you will have to eliminate the empty ‘()‘ notations.

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

Sidebar

Related Questions

i want to create a simple state machine using C but all the events
How to find a process start time on ubuntu linux machine using c language.
When I log into a remote machine using ssh X11 forwarding, Vista pops up
I'm accessing an Ubuntu machine using PuTTY, and using gcc. The default LANG environment
Is it possible to clone a virtual machine using VMware Fusion on Mac OS
I'm using this article to start a process on a remote machine using WMI.
I have installed VSTFS on a machine using the local admin. Now the machine
I'm developing on a Ubuntu 8.04 machine using Eclipse Ganymede. I installed Tomcat 5.5
I wish to send an email from my localhost machine (using PHPs mail function)
I have this membership site setup on my local machine using the ASP.NET membership

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.