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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:10:09+00:00 2026-05-27T02:10:09+00:00

Detecting a parenthesis pattern in a string This is a line (an example between

  • 0

Detecting a parenthesis pattern in a string

This is a line (an example between parenthesis).

or

This is a line(an example between parenthesis).

I need to separate both strings in:

$text = ‘This is a line.’;

$eg = ‘an example between parenthesis’;

I have this code so far:

$text = 'This is a line (an example between parenthesis)';
preg_match('/\((.*?)\)/', $text, $match);
print $match[1];

But it only brings the text inside the parenthesis. I also need the text outside the parenthesis.

  • 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-27T02:10:10+00:00Added an answer on May 27, 2026 at 2:10 am
    $text = 'This is a line (an example between parenthesis)';
    preg_match('/(.*)\((.*?)\)(.*)/', $text, $match);
    echo "in parenthesis: " . $match[2] . "\n";
    echo "before and after: " . $match[1] . $match[3] . "\n";
    

    UPDATE after clarification of question .. now with many parenthesis:

    $text = "This is a text (is it?) that contains multiple (example) stuff or (pointless) comments in parenthesis.";
    $remainder = preg_replace_callback(
            '/ {0,1}\((.*)\)/U',
            create_function(
                '$match',
                'global $parenthesis; $parenthesis[] = $match[1];'
            ), $text);
    echo "remainder text: " . $remainder . "\n";
    echo "parenthesis content: " . print_r($parenthesis,1) . "\n";
    

    results in:

    remainder text: This is a text that contains multiple stuff or comments in parenthesis.
    parenthesis content: Array
    (
        [0] => is it?
        [1] => example
        [2] => pointless
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have suggestions for detecting URLs in a set of strings? arrayOfStrings.forEach(function(string){ //
Does anyone have experience detecting identical text(); and class? here is my current code
Goal Detecting where comparisons between and copies of variables are made Inject code near
I'm detecting @replies in a Twitter stream with the following PHP code using regexes.
Possible Duplicate: PHP detecting request type (GET, POST, PUT or DELETE) This should be
Possible Duplicate: Detecting syllables in a word Assume the input string is saya sedang
I have found a solution for auto detecting links and putting them in the
I have little issue with detecting internet connection while using static IP on device.
Is there anyway of detecting a duplicate form submit with PHP? I have a
I would like some help for detecting the following expressions with RegEx: string "(x/x)"

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.