Everyone else is quite right that the sensible person uses a module for this. However, if you aren't sensible, or if you're writing for people who can't necessarily install modules on their machine, you might do something like this:
First split the HTML into chunks, and don't process bits of HTML outside < and >. Again, the wise person would use a module for this, but the rash fool would just split on ">". Then, for each chunk:
if (/name\s*=\s*['"]?(\w+)/i)
{
$name = $1;
}
The only interesting thing here is the ['"]? which makes sure that you don't grab any quotes by accident. As far as I recall, form names should only have word characters, but I am ready to be corrected. I also don't know whether the spaces between html attribute names and values are legit or not. But unless you are writing the html yourself, you can trust some foolish user to put them in.
If you just want _form_ element names, you'll also first need to test for what sort of html tag you have:
if (/<input|<select|<textarea/i)
Cheers
Dave
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.