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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:00:05+00:00 2026-06-07T17:00:05+00:00

First, yes, I know that regex should never be used to parse HTML, however,

  • 0

First, yes, I know that regex should never be used to parse HTML, however, in this situation I’m taking a long string of text (output of var_dump(), actually) and using several regexes to transform it into XHTML so I know exactly what tags I will be dealing with. The last two regexes in my sequence look for the curly braces and transform into pieces of XHTML. It works great EXCEPT for when the curly braces are contained in a string variable, which I am outputting in between <var></var> tags in a previous regex.

So, currently, I’m using: /\s*{\s*/u. What I need to do is adjust this to ignore any curly brace anywhere within the <var></var> tags.

I’ve tried using: /\s*{\s*(?!(?<!<var>)[^\{]*<\/var>)/u but that isn’t quite right. I have not yet pinpointed what the conditions are that make it not work correctly. So, I may be close with this regex or I may be way off. Hence the need for the SO expertise. Thank you.

Also, if this is simply not possible, there are other hacks I can do, ie, base64_encode() the string, stick it in the <var></var> tags and then as a last regex, base64_decode() anything surrounded by <var></var> tags. I’d prefer to find a usable regex and more importantly, simply curious if it’s 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-07T17:00:07+00:00Added an answer on June 7, 2026 at 5:00 pm

    This might work:

    \s*{\s*(?:(?!(?:.*?</var>))|(?=[^<]+<var>))
    

    Pretty much, I rephrased the question: Instead of not matching curly braces within <var>, I only match curly braces that can be proved to be outside of <var>. So, a curly brace is outside of a <var> if:

    1. It can be asserted that this is true: (?!(?:.*?</var>)), which uses a negative lookahead to ensure that we don’t hit the closing </var> tag, or
    2. It can be asserted that this is true: (?=[^<]+<var>), which uses a positive lookahead to ensure that somewhere we’ll eventually hit the opening <var> tag.

    It will definitely fail with nested <var> tags, but it seems to work with the test case I used. You can run it on RegExr and tell me what you think.

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

Sidebar

Related Questions

First off: I know that this isn't reliable for actually checking if I can
First off, yes, I know that the VS Setup Projects are evil. It's what
Yes, I know that less was in first place written for node.js. But I
I have an AXIS2/JAX-WS web service using a code first implementation (yes I know,
Yes, I've googled and I could not find the answer to this problem. First
FIRST: Yes, I know about CONCATENATE and CONTINUEIF, but I might not be smart
Iam still getting the exception lazyinitializationexception. Yes, i know that it means, that the
Let me start off by saying that this is my first real Cocoa app.
So, I have this link, that should send an AJAX request everytime it is
I know that there are a lot of questions about this topic, but unfortunately

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.