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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:14:15+00:00 2026-05-13T07:14:15+00:00

I have some text, something like this: Paragraphs of text (SOME KNOWN TEXT)Unknown Text(SOME

  • 0

I have some text, something like this:

Paragraphs of text
(SOME KNOWN TEXT)Unknown Text(SOME OTHER KNOWN TEXT)
Some additional paragraphs of text

What I want is to keep the Unknown Text, but get rid of the (SOME KNOWN TEXT) and (SOME OTHER KNOWN TEXT).

I think the preg_replace will give me what I want, but I need the regular expression to replace this:

(SOME KNOWN TEXT)Unknown Text(SOME OTHER KNOWN TEXT)

with this ..

Unknown Text

I see the preg_replace takes 3 parameters, the regex, the replacement text, and subject.

Is there a way to pass the value of unknown text to the replacement text parameter, OR, a way to reaplce the left and right pieces (SOME KNOWN TEXT) and (SOME OTHER KNOW TEXT) without removing the Unknown Text? Alternatively, is there a str_replace() solution to this?

Thanks

—UPDATE—

The (SOME OTHER KNOWN TEXT) piece may exist in other places in the text, but I don’t want it removed unless it follows the pattern of (SOME KNOWN TEXT)Unknown Text(SOME OTHER KNOWN TEXT). I am thinking the initial str_replace suggestions would not work because of this.

  • 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-13T07:14:15+00:00Added an answer on May 13, 2026 at 7:14 am

    What are the conditions? If you have:

    (SOME OTHER KNOWN TEXT)Unknown text(SOME KNOWN TEXT)

    (i.e. if the bracketing text is swapped), do you still want to remove it? Must the known text always be at the beginning or end of the line? If the answer is yes to either of these, you’re probably better off using a regex. Something like this:

    $new_text = preg_replace('/^\(SOME KNOWN TEXT\)(.+)\(SOME OTHER KNOWN TEXT\)$/m, '$1', $text);
    

    The backslashes (\) are to escape the ( and ) characters, which have a special meaning in regular expressions. I assume that you’ll want to change the content – you can remove them at that point.

    In this regex, the . is a special operator meaning "any character." It will match any character. The + means "one or more", and is a modifier on the previous operator – together, these can be interpreted as matching "one or more of any character". The ( and ) characters are used for capturing sections of the text in a subpattern. By encompassing the .+ in parentheses, we capture this to be used in the replacement. The first section surrounded by ( and ) are labelled $1 by the regex engine. If we had more, they’d be labelled $2, $3, and so on.

    If neither of these apply, you can use the str_replace function as mentioned in the other answers.

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

Sidebar

Related Questions

Imagine that you have some text like this: Asdf I want the 'A' to
I have some text that is stored in a variable like this: <div class=foo>text
I have some text inside $content var, like this: $content = $page_data->post_content; I need
If I have some text file like abc.txt the I want to the hex
If I have html like this: <li id=listItem> This is some text <span id=firstSpan>First
I am using something like this to share some text using available applications on
Suppose I have some text files (f1.txt, f2.txt, ...) that looks something like @article
say I have a piece of text like this Hello I am some text
I have something like this <td> <a href=#> <span class=foo> Link Text </span> </a>
I have some text with images inside it. For example like this texttext<img src=2011-08-15/4/img/123.JPG

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.