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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:40:15+00:00 2026-05-31T02:40:15+00:00

I have this pattern [-]{23}[ ]*Page[ ]*[0-9]*[-]{23} to extract the page number from an

  • 0

I have this pattern [-]{23}[ ]*Page[ ]*[0-9]*[-]{23}to extract the page number from an string like ----------------------- Page 1----------------------- it works fine using javascript regex implementation:

var s = "----------------------- Page 1-----------------------";
alert( s.match(/[-]{23}[ ]*Page[ ]*[0-9]*[-]{23}/) != null);

match() function returns the matched string value or null if pattern does not match with string. The above code show true

my C code:

#include <assert.h>
#include <sys/types.h>
#include <regex.h>

//... 

regex_t reg;
regmatch_t match;
char * line = "----------------------- Page 1-----------------------";
regcomp(&reg,
          "[-]{23}[ ]*Page[ ]*[0-9]*[-]{23}",
          REG_ICASE /* Don't differentiate case */
    );

int r = regexec(&reg,
         line, /* line to match */
         1, /* size of captures */
         &match,
         0); 

if( r == 0) { printf("Match!"); } else { printf("NO match!"); }

the if-statement above print NO match! I have no idea how to fix this. Thanks in advance.

  • 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-31T02:40:16+00:00Added an answer on May 31, 2026 at 2:40 am

    For the regex library to recognize the full regular expression, use REG_EXTENDED in the regcomp flag.

    it is possible to use groups?

    Do you mean capturing groups? Like this?

    #include <assert.h>
    #include <stdio.h>
    #include <sys/types.h>
    #include <regex.h>
    
    int main(void) {
      int r;
      regex_t reg;
      regmatch_t match[2];
      char *line = "----------------------- Page 1-----------------------";
    
      regcomp(&reg, "[-]{23}[ ]*Page[ ]*([0-9]*)[-]{23}", REG_ICASE | REG_EXTENDED);
      /*                                ^------^ capture page number */
      r = regexec(&reg, line, 2, match, 0);
      if (r == 0) {
        printf("Match!\n");
        printf("0: [%.*s]\n", match[0].rm_eo - match[0].rm_so, line + match[0].rm_so);
        printf("1: [%.*s]\n", match[1].rm_eo - match[1].rm_so, line + match[1].rm_so);
      } else {
        printf("NO match!\n");
      }
    
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got this regex pattern that works with my current apache log format:
I have this pattern: ~^([a-z0-9]+[a-z0-9-]+[a-z0-9]+\.([a-z]+)(\.[a-z]+)?)$~i It will match the following: xxx.xxx or xxx.xxx.xxx (number
I have a string which I store book pages. It's something like this: ///0///
i have some strings with this pattern in some files: domain.com/page-10 domain.com/page-15 .... and
I have a string like this that I need to parse into a 2D
I have this pattern written ^.*\.(?!jpg$|png$).+$ However there is a problem - this pattern
Ok so if I have this pattern: ab&bc&cd&de&ef And I need to replace all
I have this module pattern that stores a bunch of vars. I want to
I have this code: # Compare phone number phone_pattern = '^\d{3} ?\d{3}-\d{4}$' phoneNumber =
I have this piece of code: function func1(text) { var pattern = /([\s\S]*?)(\<\?(?:attrib |if

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.