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

  • Home
  • SEARCH
  • 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 8805319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:50:12+00:00 2026-06-14T01:50:12+00:00

I have some text like this, it’s written in a custom markdown style format.

  • 0

I have some text like this, it’s written in a custom markdown style format. For example:

[Lorem ipsum] 
Dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 

[Ut wisi] 
[Enim ad minim veniam](a), quis nostrud exerci tation ullamcorper. 
suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat. 
Vel illum dolore eu feugiat nulla facilisis at vero.
[Ros et accumsan et iusto odio dignissim](b) qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. 

[[Nam liber]](c)
Tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.

As you can see there are square brackets surounding headings, and there are square brackets followed by parenthesis containing a letter which is what I am trying to match with a regex. The regex I’m trying to use is this:

preg_match_all("#\[(.*?)\]\(([a-z]+)\)#is",$html,$matches)

The problem with this ^ one is it matches from [Lorem ipsum] down to the end of (a).

I could also use the following, however I need to be able to include headings with their square brackets so this doesn’t work correctly:

preg_match_all("#\[([^]]+)\]\(([a-z]+)\)#is",$html,$matches)

After some reading up, I suspect what I need is a lookahead, however I’ve not been able to get my head around them. Any help much appreciated.


Clarification

I’m basically looking to be able to wrap any part of some text with the square brackets/parenthesis combination and then be able to match them with regex without existing square brackets anywhere causing conflicts. Example text:

[[Lorem ipsum]](a)
Dolor sit amet, [consectetuer adipiscing elit](b), sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 

Desired matches:

[[Lorem ipsum]](a)
[consectetuer adipiscing elit](b)

Or… more complex

[[Lorem ipsum]
Dolor sit amet, sed diam nonummy nibh euismod](a) tincidunt ut laoreet dolore magna aliquam erat volutpat. 

Desired match:

[[Lorem ipsum]
Dolor sit amet, sed diam nonummy nibh euismod](a)

Is it possible?

  • 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-06-14T01:50:14+00:00Added an answer on June 14, 2026 at 1:50 am

    Here you go.

    preg_match_all("~
        \[(              # open outer square brackets and capturing group
        (?:              # open subpattern for optional inner square brackets
            [^[\]]*      # non-square-bracket characters
            \[           # open inner square bracket
            [^[\]]*      # non-square-bracket characters
            ]            # close inner square bracket
        )*               # end subpattern and repeat it 0 or more times
        [^[\]]*          # non-square-bracket characters
        )]               # end capturing group and outer square brackets
        (?:              # open subpattern for optional parentheses
            \((          # open parentheses and capturing group
            [a-z]+       # letters
            )\)          # close capturing group and parentheses
        )?               # end subpattern and make it optional
        ~isx",
        $input,
        $matches);
    

    And the regex in one line:

    "~\[((?:[^[\]]*\[[^[\]]*])*[^[\]]*)](?:\(([a-z]+)\))?~isx"
    

    Working demo

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

Sidebar

Related Questions

I have some text where unicode is written as text like this There areu25ba
Lets say we have some text: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Example: I have some text, like this php code if(empty($condition)) { // work here...
I have some text with images inside it. For example like this texttext<img src=2011-08-15/4/img/123.JPG
I have some text like this: এর জন্য বুদ্ধির (Reason) প্রয়োজন নেই, প্রয়োজন নিজের
I have some text that is stored in a variable like this: <div class=foo>text
Hey, I have some text that is formatted like this: [quote]foo text[/quote] and I
If I have some xml like this: <mynode> <mysubnode> <mysubsubnode>hello world</mysubsubnode> some more text
i have a string like this one: $string = some text http://dvz.local/index/index/regionId/28 http://stuff.kiev.ua/roadmap_page.php http://192.168.3.192/roadmap_page.php
I have some HTML like this: <input type=radio class=MyRadio name=TheName> <label for=TheLabel>the text</label> How

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.