About regura expression only for outside of html tags.

G

G&G

Have any idea about regular expression ?


I tried to change any numeric letter to Zero like following;
$aaa = ereg_replace ("|0-9|", "0", $sentence);
This seems working perfect.

My question is how I can do this function only for outside of html tags.
I don't want any numeric letters to be changed inside html tags.

Thanks for further response.

Regards,
Mo
 
A

Anno Siegel

G&G said:
Have any idea about regular expression ?


I tried to change any numeric letter to Zero like following;
$aaa = ereg_replace ("|0-9|", "0", $sentence);
This seems working perfect.

My question is how I can do this function only for outside of html tags.
I don't want any numeric letters to be changed inside html tags.

HTML cannot reasonably be parsed by a regex alone. Use a HTML parser
from CPAN.

Anno
 
T

Tad McClellan

G&G said:
I don't want any numeric letters to be changed inside html tags.


What is a "numeric letter"?

Perhaps you meant "numeric character" instead?
 
M

Mo

Thanks for your answer Anno.

Would you please make clear your word little more ?

"Use a HTML parser from CPAN"

I don't really get it, since I'm just beginner on programming.

Regards
Mo
 
H

Helgi Briem

First, don't start a new thread to followup an existing
article unless the subject changes radically.

Second, don't top-post. It annoys the regulars and
seriously damages your chances of receiving
useful answers to your questions. If you don't know
what top-posting is, read:
http://www.catb.org/~esr/jargon/html/T/top-post.html

For further guidelines on posting to comp.lang.perl.misc read:

http://mail.augustmail.com/~tadmc/clpmisc.shtml

For more information about netiquette in general, see the
"Netiquette Guidelines" at:

http://andrew2.andrew.cmu.edu/rfc/rfc1855.html

Would you please make clear your word little more ?

"Use a HTML parser from CPAN"

I don't really get it, since I'm just beginner on programming.

He means to go to the Comprehensive Perl Archive Network,
where all publicly available Perl modules are stored:

http://search.cpan.org/

There you can find, download and install a HTML parser module.

The standard one is HTML::parser which is part of the core
in recent Perl distributions, but it is a little hard to use for
a beginner.

HTML::TokeParser::Simple is much easier to use and
there are even simpler ones.

Contrary to popular opinion, parsing HTML *is* close to
rocket science and is not a job for a beginner's hand coding.
 
M

Mo/G&G

It works perfect.
$aaa = preg_replace("/((<[^>]*)|\d)/e", '"\2"=="\1"? "\1":"0"', $sentence);

Thanks

Regards,
Mo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top