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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:40:28+00:00 2026-05-30T22:40:28+00:00

How do I use preg_match to return an array of all substrings that match

  • 0

How do I use preg_match to return an array of all substrings that match (:)?

For example if I have a string that is:

My name is (:name), my dog's name is (:dogname)

I want to use preg_match to return

array("name", "dogname");

I tried using this expression…

preg_match("/\(:(?P<var>\w+)\)/", $string, $temp);

But it only returns the first match.

Can anyone help me?

  • 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-30T22:40:29+00:00Added an answer on May 30, 2026 at 10:40 pm

    First off, you want preg_match_all (find all matches), not preg_match (check if there are any matches at all).

    And for the actual regex, the best technique is to search for (: and then search for any character except for )

    $string = "My name is (:name), my dog's name is (:dogname)";
    
    $foundMatches = preg_match_all('/\(:([^)]+)\)/', $string, $matches);
    $matches = $foundMatches ? $matches[1] : array(); // get all matches for the 1st set of parenthesis. or if there were no matches, just an empty array
    
    var_dump($matches);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use preg_match to return an array of every match for parenthesized
I'm trying to use preg_match to return all the URL's that are inclosed in
assuming we have this regex: preg_match('/\b(xbox|xbox360|360|pc|ps3|wii)\b/i' , $string, $matches); now, whenever the regex match
I have this code I currently use to validate emails: return (bool) preg_match('/^([a-z0-9\+\_\-\.]+)@([a-z0-9\+\_\-\.]{2,})(\.[a-z]{2,4})$/i', $arg0);
I'm trying to use preg_match to extract info from href=domain.com/subdir/?key=value The info I want
How would I use the PHP function preg_match() to test a string to see
I have an array that is structured as such: $data = array( abc=>array( label
I have this query: list[One]=1&list[Two]=2&list[Apple]=fruit this is the regex I use to return the
So I have two strings, and I want to compare and return the differences.
I haw got a array of directory's that i wont to use for the

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.