The problem is likely to be worse than just lack of quote. Once you fix that you will still have the people who forget the closing </a>, or who cock up about 50 other simple syntax rules. I'd suggest you simply have a preview page as we have here in perlmonks where the user can see what his post really looks like.
If you want to validate just what you mention then a checker regex is
my ($openquote, $uri, $closer) = m!<a\s+href\s*=\s*(['"])([^>'"]+)(.)!
+i;
Then
- its valid if $openquote eq $closer.
- trailing quote omitted if $closer eq '>'.
- else trailing quote mismatched.
Its up to you to figure out the replacements and/or whether to do it as a single regex - probably better not to try as it will be ugly. Probably its best to reject the post and make the user fix it, that way they won't make a mistake again.
Dingus
Enter any 47-digit prime number to continue.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.