regular expression question(s)

I

inderpaul_s

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 ?
 
P

Paul Lalli

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
 
M

Matt Garrish

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 ?

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
 
I

inderpaul_s

Paul said:
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

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 ?
 
I

inderpaul_s

Thanks works if I'm signed in just as a normal user but NOT root....why
is that ?
 
I

inderpaul_s

Thanks works if I'm signed in just as a normal user but NOT root....why
is that ?
 
J

Jürgen Exner

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

Jürgen Exner

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
 

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
474,181
Messages
2,570,969
Members
47,536
Latest member
VeldaYoung

Latest Threads

Top