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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:06:27+00:00 2026-06-02T14:06:27+00:00

I have a PHP preg_match_all and REGEX question. I have the following code: <?php

  • 0

I have a PHP preg_match_all and REGEX question.

I have the following code:

<?php

$string= 'attribute1="some_value" attribute2="<h1 class=\"title\">Blahhhh</h1>"';

preg_match_all('/(.*?)\s*=\s*(\'|"|&#?\w+;)(.*?)\2/s', trim($string), $matches);

print_r($matches);

?>

That does not seem to pickup escaped quotes for the instance that I want to pass in HTML with quotes. I have tried numerous solutions for this with the basic quotes inside quotes REGEX fixes, but none seem to be working for me. I can’t seem to place them correctly inside this pre-existing REGEX.

I am not a REGEX master, can someone please point me in the right direction?

The result I am trying to achieve is this:

Array
(
    [0] => Array
        (
            [0] => attribute1="some_value"
            [1] =>  attribute2="<h1 class=\"title\">Blahhhh</h1>"
        )

    [1] => Array
        (
            [0] => attribute1
            [1] =>  attribute2
        )

    [2] => Array
        (
            [0] => "
            [1] => "
        )

    [3] => Array
        (
            [0] => some_value
            [1] => <h1 class=\"title\">Blahhhh</h1>
        )
)

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-06-02T14:06:28+00:00Added an answer on June 2, 2026 at 2:06 pm

    You can solve this with a negative lookbehind assertion:

    '/(.*?)\s*=\s*(\'|"|&#?\w+;)(.*?)(?<!\\\\)\2~/'
                                     ^^^^^^^^^
    

    The closing quote should not be prepended by \. Gives me:

    Array
    (
        [0] => Array
            (
                [0] => attribute1="some_value"
                [1] =>  attribute2="<h1 class=\"title\">Blahhhh</h1>"
            )
    
        [1] => Array
            (
                [0] => attribute1
                [1] =>  attribute2
            )
    
        [2] => Array
            (
                [0] => "
                [1] => "
            )
    
        [3] => Array
            (
                [0] => some_value
                [1] => <h1 class=\"title\">Blahhhh</h1>
            )
    )
    

    This regex ain’t perfect because it of the entity you but in there as delimiter, like the quotes it can be escaped as well with \. No idea if that is really intended.

    See also this great question/answer: Split string by delimiter, but not if it is escaped.

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

Sidebar

Related Questions

/<table[\s]+cellspacing=0[\s]+class=cj(?:.*?)[\s]+id=(?:.*?)>(?:.*?)value=(.*?)(?:.*?)<td[\s]+class=dep>(.*?)<\/td>(?:.*)(?:<td[\s]+class=arr>(.*?)<\/td>)+(?:.*?)<\/table>/ This is my current regex string, used in PHP with preg_match_all() . I
I have the following regex in a PHP script $total_matches = preg_match_all('{ <a\shref= (?<link>[^]+)
There has always been a confusion with preg_match in php. I have a string
I have PHP code which connects to MySql and encodes data to JSON. Later
preg_match(/\w+/, $s, $matches); I have the PHP code above. I use it to match
i have this regex string that i got from a website to pull emails
I have some JavaScript, which is generated by PHP code, using a template. The
In php, I have used preg_match_all() to find keywords (using the format %keyword%) in
Greetings all, I have yet another RegEx question. I have done hours of searching
I have the following string: key:surname +++ value:Tesla|||key:name +++ value:Nikola|||key:age +++ value:86||| How with

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.