Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

regular expression question(s)

瀏覽次數:0 次
跳到第一則未讀訊息

inder...@yahoo.com

未讀,
2006年4月12日 下午6:53:502006/4/12
收件者:
Hello everyone I've got these regular expressions and need helping
understanding them: Can someone help me out with details of each
expression ? Thanks.

1. /<[^>]+>/ # matches <open ..>, <foo >, etc. ?
2. /<\/?[^>]+>/ # matches any open or close tag ?
3. s/<img[^>]*>/hello/gi; #what does exacly hello replace ?

Paul Lalli

未讀,
2006年4月12日 晚上7:28:262006/4/12
收件者:
inder...@yahoo.com wrote:
> Hello everyone I've got these regular expressions and need helping
> understanding them: Can someone help me out with details of each
> expression ? Thanks.
>
> 1. /<[^>]+>/ # matches <open ..>, <foo >, etc. ?

the [ ] mean to match any of the characters contained within. When a ^
is the first character of one of these character classes, it means
"not". And then + means "one or more of the previous". So this
matches:
a less than, one-or-more not-greaterthans, a greater than.

> 2. /<\/?[^>]+>/ # matches any open or close tag ?

When trying to match a / inside a regular expression that uses / as the
delimiters, it is necessary to "escape" it, by preceding it with a
backslash. The ? means "0 or 1 of hte previous" So this matches:
less than, 0 or 1 slashes, one-or-more not-greaterthans, greater than.

> 3. s/<img[^>]*>/hello/gi; #what does exacly hello replace ?

hello replaces the entire match. Which in this case is:
less than, i, m, g, 0 or more not-greaterthans, greater than.

So that entire string, from the < to the >, is replaced by 'hello'

You would do well to read some documentation:
perldoc perlretut
perldoc perlre

Paul Lalli

Matt Garrish

未讀,
2006年4月12日 晚上7:36:402006/4/12
收件者:

<inder...@yahoo.com> wrote in message
news:1144882430....@j33g2000cwa.googlegroups.com...

The last one switches <img> tags with the word hello. The other do what they
say, albeit poorly. You shouldn't try to parse markup languages with regular
expressions unless you can trust the input (and even then it's often a bad
idea).

I'd suggest a skim through perlretut, perlrequick and perlre if you don't
understand character classes or quantifiers.

Matt


inder...@yahoo.com

未讀,
2006年4月12日 晚上8:14:172006/4/12
收件者:

Thanks for the help everyone. I tried running the perldoc perlre but
get the error "Superuser must not run /usr/bin/perldoc without security
audit and taint checks" ? what does this mean ?

Jim Gibson

未讀,
2006年4月12日 晚上9:01:502006/4/12
收件者:
In article <1144887257....@v46g2000cwv.googlegroups.com>,
<"inder...@yahoo.com"> wrote:


> Thanks for the help everyone. I tried running the perldoc perlre but
> get the error "Superuser must not run /usr/bin/perldoc without security
> audit and taint checks" ? what does this mean ?
>

It means you are logged in as root and trying to do things that do not
require root privileges. This can be a security risk, so Perl doesn't
let you do it. Try logging in as a normal user.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

inder...@yahoo.com

未讀,
2006年4月12日 晚上9:34:142006/4/12
收件者:
Thanks works if I'm signed in just as a normal user but NOT root....why
is that ?

inder...@yahoo.com

未讀,
2006年4月12日 晚上9:36:122006/4/12
收件者:

Jürgen Exner

未讀,
2006年4月12日 晚上9:38:592006/4/12
收件者:
inder...@yahoo.com wrote:
> I tried running the perldoc perlre but
> get the error "Superuser must not run /usr/bin/perldoc without
> security audit and taint checks" ? what does this mean ?

It means that you are not following standard security operation procedures.
Working as root when not needed is a blatant security hole about the size of
the Mediterranian Sea. There are larger ones, but not many.

Of course this has nothing to do with Perl.

jue


Jürgen Exner

未讀,
2006年4月12日 晚上9:41:272006/4/12
收件者:
inder...@yahoo.com wrote:
> Thanks works if I'm signed in just as a normal user but NOT
> root....why is that ?

What works as normal user and not as root? Please quote appropriate
content -as has been customary for 2 decades- such that people have a chance
to know what you are talking about.

jue


inder...@yahoo.com

未讀,
2006年4月12日 晚上10:32:412006/4/12
收件者:
Many thanks to all you. Regards

inder...@yahoo.com

未讀,
2006年4月12日 晚上11:11:472006/4/12
收件者:
0 則新訊息