I'm currently writing something that uses a variant of bbcode to allow the user to create an HTML form. It works so far, but in an effort to idiot-proof it, I've decided to make putting quotes around the attributes optional. This is the regexp that does that:
/name=(")? # "name" attribute followed by optional quote ([^(?(1)"|\s\])]+) # if the quotation mark was present, match until an +other one, otherwise stop at whitespace or a bracket (?(1)") # match end quote, if applicable /xi
What I'm wondering now is if I should allow users to escape quotes in the attribute. I know this is more trouble than it's worth, but I'm curious. How would I go about ignoring the quotation marks preceded by a backslash? I've tried a negative lookbehind within the conditional, but it didn't work.

In reply to Regular expression help: Taking HTML-like attributes with optional quotes by Cap'n Steve

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.