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

  • Home
  • SEARCH
  • 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 117133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:17:16+00:00 2026-05-11T03:17:16+00:00

I have a regular expression like this (much simplified): ^(ab)*$ And am matching against

  • 0

I have a regular expression like this (much simplified):

^(ab)*$ 

And am matching against this:

abababababababab 

When I run it through preg_match:

preg_match('/$(ab)*$/', 'abababababababab', $matches); print_r($matches); 

I get this:

Array (     [0] => abababababababab     [1] => ab ) 

Wheras I expect this:

Array (     [0] => abababababababab     [1] => ab     [2] => ab     [3] => ab     [4] => ab     [5] => ab     [6] => ab     [7] => ab     [8] => ab } 

How can I get what I expect?

(Note that the subexpression could be more complicated, e.g. ([aA][bB]), and I want the matched expressions in their order in the subject.)

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T03:17:17+00:00Added an answer on May 11, 2026 at 3:17 am

    Do it by using preg_match_all like this:

    preg_match_all('/(ab)/', 'abababababababab', $matches); print_r($matches); 

    Remember that preg_match only provides the first match and that preg_match_all has the same functionality, but returns all. Also note that now the regular expression has changed. If you use the asterisk, it’ll likely consume the entire string on the first match. You could, however, try something like (ab)*? to make it nongreedy.

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

Sidebar

Related Questions

I have this regular expression: ^\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$ however it is failing when i have an
I have a regular expression to match a persons name. So far I have
Does anyone have a regular expression handy that will match any legal DNS hostname
I have the following regular expression : I figured out most of the part
I have a Python regular expression that contains a group which can occur zero
What follows is a regular expression I have written to match multi-line pre-processor macros
I have the following very simple Javascript-compatible regular expression: <script type=text/javascript id=(.+) src=([^]+)> I
Over the years I have slowly developed a regular expression that validates most email
Does anyone have any suggestions (or a regular expression) for parsing the HTTP Accept
I need some help to model this regular expression. I think it'll be easier

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.