set html "
<a href=http://valsignalandet.com/cgi-bin/cgiwrap/ppowell/polldisplay.cgi?maxPolls=3&startPollID=9>Click
Here for "The Välsignalandet Poll"</a>
<script>
if (document.all && document) alert('Hello & Welcome');
</script>
"
In the variable html I want to be able to "escape" all occurrences of
ampersands so that when rendered html will look like this:
set html "
<a href=http://valsignalandet.com/cgi-bin/cgiwrap/ppowell/polldisplay.cgi?maxPolls=3&startPollID=9>Click
Here for &quot;The V&#228;lsignalandet Poll&quot;</a>
<script>
if (document.all && docuent) alert('Hello & Welcome');
</script>
"
What I basically want to do is the following:
1. If it is & followed by alphanumeric followed by ; replace with
&[a-zA-Z0-9]+;
2. If it is & alone, leave alone.
3. If it is && alone, leave alone.
4. If it is & followed by stuff that is NOT containing all
alphanumeric or ending in ; leave along (e.g.
?maxPolls=3&startPollID=9> )
Can someone help me figure out what to do? Every pattern of a regsub
I have used has produced only partial results or no results at all,
and every single instance I listed above must all occur every time.
Thanks
Phil
first of all do you realize that in
regsub pattern source {x&x} var
& will be replaced by the substring that was matched?
and to turn this off you backslash the &
regsub pattern source {x\&x} var
what happens with
regsub -all {&([a-zA-Z0-9]+;)} source {\&\1} var
(\1 is replaced with substring matched by the parenthesised re)
Or even:
regsub -all {&(?=\w+;)} $source {\&} var
Donal.
--
[Seen in a discussion about automounters; names omitted to protect the guilty]
A> "I don't know. All I know is that it wasn't there until I tried to use it"
B> "You mean like some guy's cat?"
A> "I didn't mount his cat. The photo's are fake"
regsub -all {\&([a-zA-Z0-9]+;)} $text {\&\1} text
Phil
mair_...@www.yahoo.com (rand mair fheal) wrote in message news:<mair_fheal-04...@c45.ppp.tsoft.com>...
regsub -all {&(?=[a-zA-Z0-9#]+;)} $stuff {\&} stuff
Thanx all!
Phil
"Donal K. Fellows" <fell...@cs.man.ac.uk> wrote in message news:<3C396CA6...@cs.man.ac.uk>...
basically the parens with ?= is a lookahead constraint - meaning
it is not part of the match, but the match (just an ampersand) is
only considered a match if followed by something that matches "[a-zA-Z0-9#]+;"
also see the wiki for more regexp stuff :
http://mini.net/tcl/986.html
http://mini.net/tcl/989.html
http://mini.net/tcl/1345.html
Bruce
Hmm... You do realize that transforming:
>>> if (document.all && document) alert('Hello & Welcome');
to:
>>> if (document.all && docuent) alert('Hello & Welcome');
is completely at odds with rule 2 below?
>>> What I basically want to do is the following:
>>>
>>> 1. If it is & followed by alphanumeric followed by ; replace with
>>> &[a-zA-Z0-9]+;
>>> 2. If it is & alone, leave alone.
>>> 3. If it is && alone, leave alone.
>>> 4. If it is & followed by stuff that is NOT containing all
>>> alphanumeric or ending in ; leave along (e.g.
>>> ?maxPolls=3&startPollID=9> )
Which do you want?
Donal.
-- Fools have been claiming the death of Unix since it was developed in the
late 60's. Unfortunately (for them) the death of Unix keeps getting
postponed, due to circumstances beyond their control.
-- Terry Porter <tjpo...@gronk.porter.net>