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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:57:38+00:00 2026-05-31T00:57:38+00:00

Hi how do I do a preg match on $string1 = [%refund%]processed_by $string2 =

  • 0

Hi how do I do a preg match on

$string1 = "[%refund%]processed_by"

$string2 = "[%refund%]date_sent"

I want to grab the bits inside %% and then remove the [%item%] altogether. leaving just the “proccessed_by” or “date_sent” I have had a go below but come a bit stuck.

$unprocessedString = "[%refund%]date_sent"

$match   =  preg_match('/^\[.+\]/', $unprocessedString);
$string  =  preg_replace('/^\[.+\]/', $unprocessedString);

echo $match; // this should output refund

echo $string; // this should output date_sent
  • 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-31T00:57:41+00:00Added an answer on May 31, 2026 at 12:57 am

    Your problem is with your use of the preg_match function. It returns the number of matches found. But if you pass it a variable as a third parameter, it stores the matches for the entire pattern and its subpatterns in an array.

    So you can capture both of the parts you want in subpatterns with preg_match, which means you don’t need preg_replace:

    $unprocessedString = "[%refund%]date_sent"
    preg_match('/^\[%(.+)%\](.+)/', $unprocessedString, $matches);
    echo $matches[1]; // outputs 'refund'
    echo $matches[2]; // outputs 'date_sent'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to match a string inside an HTML for example I want to
first, this is using preg. String I'm trying to match: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa b c d
I'm trying to do a preg match all on the response below to get
I want to build pattern for preg_match that will match any string with length
In PHP using preg_match I want to match one of many multicharacter strings (e.g.
I want to find and match strings that contain no HTML tags but <br/>
preg_match() gives one match. preg_match_all() returns all matches. preg_split() returns all splits. How can
Is there a way to tell preg_match_all to use the third match it finds
We can easily check for a match in a string if (preg_match(/happy/i, happy is
I've been looking at this code and it's supposed to match my $input 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.