Home > Archive > PERL CGI Beginners > January 2006 > The general rexexp.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
The general rexexp.
|
|
|
| What is the general solution when I would exchange to pieces of text,
that even include HTML-tagging?
In other words how to do this:
s#ANYTHING#SOMETHING#g
The general froblem I've met was a sign corresponding to the rexep
signs. So, how to ocupy the text the way that rexep would not reflect on
the signs the text pieces can contain?
Thank You.
| |
| Paul Lalli 2006-01-26, 7:55 am |
| Stass wrote:
> What is the general solution when I would exchange to pieces of text,
> that even include HTML-tagging?
> In other words how to do this:
>
> s#ANYTHING#SOMETHING#g
>
> The general froblem I've met was a sign corresponding to the rexep
> signs. So, how to ocupy the text the way that rexep would not reflect on
> the signs the text pieces can contain?
In general, you need to backslash any "special" characters in a regular
expression if you don't want them to be special:
s/foo\+/bar-/;
will change "foo+" to "bar-", rather than looking for "one or more
foo".
If what you want to replace is within a variable, there is a special
backslash sequence that will automatically backslash any special
characters following it:
s/string with \Q$special\E characters/new string/;
That is, surround whatever text might contain special characters with
\Q \E.
HOWEVER, are you sure you're going about this the right way? You said
you're translating HTML text. Are you just trying to translate things
like < to < and & to &? If so, you probably don't want to roll
your own s/// solution. Use a pre-made solution like
http://search.cpan.org/~gaas/HTML-P...TML/Entities.pm
Paul Lalli
| |
| Ing. Branislav Gerzo 2006-01-26, 6:55 pm |
| Stass [S], on Thursday, January 26, 2006 at 16:54 (+0600) made these
points:
S> s#ANYTHING#SOMETHING#g
$anything = "html text";
s/\Q$anything/something/g;
--
How do you protect mail on web? I use http://www.2pu.net
["Bother," said Pooh as he entered the Badlands.]
|
|
|
|
|