nick wrote:
> Hello, how to use the perl regular express to do:
That is "regular expression", not "regular express". It surely has nothing
to do with "fast"
> In a html file, replace all the underscore "_" to "-" for the alt
> attribute of <area> tags (only for the alt of area tag)? And convert
> the alt attribute to uppercase.
Contrary to popular believe parsing HTML correctly is close to rocket
science and while it may be possible to do so with REs alone, nobody in his
right mind would try it.
Use an HTML parser to parse the HTML code, further details please see the
FAQ "perldoc -q html": "How do I remove HTML from a string?"
Then it is trivial to isolate the correct attribute values and do the
necessary replacing. But even then I wouldn't use a regular expression
because there are better, more targeted functions:
- perldoc -f uc
- perldoc -f tr
> For example:
>
> <area shape="rect" alt="abc_123"> will be converted to
> <area shape="rect" alt="ABC-123">
>
> Can this be done in one step?
Once you have isolated the attribute value, then yes. But why?
jue