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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:35:12+00:00 2026-05-29T12:35:12+00:00

I am using a regex pattern to find instances of [code][/code] BB tags. (This

  • 0

I am using a regex pattern to find instances of [code][/code] BB tags. (This is in PHP with pearl-type regex using preg_match / preg_relace / etc)

'~\[code\](.*?)\[\/code\]~is'

Well, my question is how can I make it so somebody could type something like:

[code][code]code here[/code][/code]

The purpose of typing this would be to demonstrate to a newbie how to place their code into [code][/code] tags.

Currently if I type that, the regex will stop at the 1st instance of “[/code]” and not keep looking ahead to see the 2nd instance of “[code]”

I can’t post images since I’m a new user, but here is a screenshot of the output:
https://i.stack.imgur.com/7gS6x.png

I know there is a term in regex called “positive look ahead” and “negative look ahead”, but I’m not quite sure what they mean, or if they are relevant to my situation. Could someone please give me a hand? Thank you.

EDIT: I’m sorry but I don’t seem to have enough rep to +1 anything. I really appreciate your help, and it was so fast.

  • 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-29T12:35:12+00:00Added an answer on May 29, 2026 at 12:35 pm

    If you want to cover also the case that there can be more code between the two closing tags you can try this one

    \[code\].*?\[\/code\](?:(?:(?!\[code\]).)*\[\/code\])?
    

    See it here on Regexr

    The first part \[code\].*?\[\/code\] is matching from the first opening tag to the first closing tag.

    Then comes the tricky part that is now optional. (?:(?:(?!\[code\]).)*\[\/code\])? is matching characters, if the there is not an opening tag following, till the last closing tag found.

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

Sidebar

Related Questions

I'm using PHP. I'm trying to get a Regex pattern to match everything between
i need to find few words or matching pattern using a Javascript. this is
I tried writing a program in Java using regex to match a pattern and
I am using the matches string builtin and need to run a regex pattern
What's the regex to match a square bracket? I'm using \\] in a pattern
I'm trying to write a regex pattern that will find numbers with two leading
This is a homework assignment and my first experience using RegEx. I am starting
Using ICU 4.0 regex library, I find that the following regex is exhibiting exponential
I'm trying to use RegEx to find a pattern within a pattern. Specifically what
I'm using Sybase 12.5.3, and want/need to do regex pattern matching. The Sybase help

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.