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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:30:03+00:00 2026-05-12T05:30:03+00:00

those reqular expressions drive me crazy. I’m stuck with this one: test1:[[link]] test2:[[gold|silver]] test3:[[out1[[inside]]out2]]

  • 0

those reqular expressions drive me crazy. I’m stuck with this one:

test1:[[link]] test2:[[gold|silver]] test3:[[out1[[inside]]out2]] test4:this|not

Task:
Remove all [[ and ]] and if there is an option split choose the later one so output should be:

test1:link test2:silver test3:out1insideout2 test4:this|not

I came up with (PHP)

$text = preg_replace("/\\[\\[|\\]\\]/",'',$text); // remove [[ or ]]

this works for part1 of the task. but before that I think I should do the option split, my best solution:

$text = preg_replace("/\\[\\[(.*\|)(.*?)\\]\\]/",'$2',$text);

Result:

test1:silver test3:[[out1[[inside]]out2]] this|not

I’m stuck. may someone with some free minutes help me? Thanks!

  • 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-12T05:30:03+00:00Added an answer on May 12, 2026 at 5:30 am

    This is impossible to do in one regular expression since you want to keep content in multiple “hierarchies” of the content. It would be possible otherwise, using a recursive regular expression.

    Anyways, here’s the simplest, most greedy regular expression I can think of. It should only replace if the content matches your exact requirements.

    You will need to escape all backslashes when putting it into a string (\ becomes \\.)

    \[\[((?:[^][|]+|(?!\[\[|]])[^|])++\|?)*]]
    

    As others have already explained, you use this with multiple passes. Keep looping while there are matches, performing replacement (only keeping match group 1.)

    Difference from other regular expressions here is that it will allow you to have single brackets in the content, without breaking:

    test1:[[link]] test2:[[gold|si[lv]er]]
    test3:[[out1[[in[si]de]]out2]] test4:this|not
    

    becomes

    test1:[[link]] test2:si[lv]er
    test3:out1in[si]deout2 test4:this|not
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 10 regular expressions and 1 one string which may or may not
I use a bunch of locale-dependent Regular Expressions in my project, For example (a
I have a query: SELECT * from arrc_Voucher WHERE VoucherNbr REGEXP ^1002 This works
TL;DR: I need to insert a TextBox into a PlaceHolder wherever I see a
When we have a string that contains space characters: var str = ' A
Essentially I want to know if a specific XSD schema can be replaced by
For example, I want to test a postcode is valid so I test the
I am trying to extract values from a MySQL insert command in Java. The
I'm performing a regular expression using the match() method on a string that comes
How can I customize regular expression to allow alpha-numeric values,@ and dot. I want

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.