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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:19:20+00:00 2026-05-28T14:19:20+00:00

I have a plugin tag [crayon …] that may or may not be rendered

  • 0

I have a plugin tag [crayon ...] that may or may not be rendered in a <p></p> block like so:

<p>This is a <b>sentence</b> [crayon ...] The Crayon [/crayon] of words. </p>

Since my tag is replaced by a <div> tag, the <p> is left disjoint from </p> and the browser closes it for me, leaving a blank paragraph above my plugin. In any case, the markup is invalid and has weird outcomes. My problem is that I need to detect if [crayon lies between a <p></p> block. I have found two ways so far:

  1. Use <p(?:\s+[^>]*)?>(.*?)</p(?:\s+[^>]*)?> and search for [crayon in the capture.
  2. Use <p[^>]*>(?:[^<]*<(?!/?p(\s+[^>]*)?>)[^>]+(\s+[^>]*)?>)*[^<]*\[crayon for the case of <p>...[crayon where … doesn’t contain a </p> or <p> and a similar method for a </p> after the [crayon] tag.

The second method is harder to read but will fail if a </p> is captured before my tag. It doesn’t require any further processing to find my tag within the <p></p> like the first. However, the first regex is much simpler and will execute quicker. Which should I use, and is there a better way?

EDIT:

For method 2, this beast works:

<p[^<]*>(?:[^<]*<(?!/?p(\s+[^>]*)?>)[^>]+(\s+[^>]*)?>)*[^<]*((?:\[crayon[^\]]*\].*?\[/crayon\])|(?:\[crayon[^\]]*/\]))(?:[^<]*<(?!/?p(\s+[^>]*)?>)[^>]+(\s+[^>]*)?>)*[^<]*</p[^<]*>

  • 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-28T14:19:21+00:00Added an answer on May 28, 2026 at 2:19 pm

    Edit with improved regex, notice I also stole your open p tag detection ;). On PHP, had to add the s modifier for multi line match:

    /(?<!<!--)<p[^<]*>(?:[^<]*<(?!/?p(\s+[^>]*)?>)[^>]+(\s+[^>]*)?>)*[^<]*\[crayon.*?\].*?\[\/crayon\].*?<\/p>(?!(\s)?-->)/s
    

    The following string was used for testing. 5 matches expected, 179 steps taken (the single regex from question took 285 steps):

    <p>This is a <b>sentence</b> [crayon]...[/crayon] of words.</p>
    <p class="large"> Paragraph with parameters [crayon]...[/crayon]</p>
    <p>[crayon with-parameters=true]...[/crayon]</p>
    <p>
    Multiline paragraph [crayon]...[/crayon].
    Lorem ipsum.
    </p>
    <p>...</p><p>[crayon]...[/crayon]</p>
    <!-- <p> --> This is a <b>sentence</b> [crayon]...[/crayon] of words.<!-- </p> -->
    <pizza>yummy</pizza>
    

    Any improvement?

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

Sidebar

Related Questions

I have a plugin that is loaded by this application.. This plugin calls some
I recently started testing web_app_theme plugin. In Create button I have something like this...
I have a plugin that changes the look of select html tag on all
I have this ice face tag in my .jsp page: <ice:panelPopup modal=true rendered=true visible=#{popupInfoMessageBean.showPopupPanel}
I have a plugin for an RCP app that uses BIRT. I have a
We have a plugin system on a WCF service that checks libraries placed in
does jquery have any plugin that prevents entering any input to a textbox that
Does jQuery validation plugin have some dependencies? For example, I saw blogposts that said
I have successfully set up this plugin before so I am curious as to
I have a native Delphi TFrame that emulates Roy Tanck's Cumulus Tag Cloud viewer,

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.