Closed Thread Icon

Topic awaiting preservation: Regular Expression - mr.MaX your favourite stuff :) (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12133" title="Pages that link to Topic awaiting preservation: Regular Expression - mr.MaX your favourite stuff :) (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Regular Expression - mr.MaX your favourite stuff :) <span class="small">(Page 1 of 1)</span>\

 
Smash
Bipolar (III) Inmate

From: Stockholm, Sweden
Insane since: Sep 2001

posted posted 03-23-2002 17:40

Hi everybody, I have a pretty coool question for you guys.

I want to do the following in VBScript!

I want to replace "<zork>ANYTHING</zork>"
to "<a href="test.asp?name=ANYTHING">ANYTHING</a>"

And then on another page I would like to replace "<a href="test.asp?name=ANYTHING">ANYTHING</a>"
back into "<zork>ANYTHING</zork>"

So in the database it will be saved as <zork>ANYTHING</zork> but when i view it i want to replace it to a link.

The thing is that ANYTHING could be ANYTHING entered...

I really hope you can help me with this one!

THANKS IN ADVANCE!
-----------------------
SMASH




[This message has been edited by Smash (edited 03-23-2002).]

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 03-23-2002 18:03

Sounds like a job for XML and an XML parser.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 03-23-2002 19:14

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 03-23-2002 19:59

Although, I don't work in ASP, the following code should do the trick (it's actually JavaScript, set to run on server):

<SCRIPT LANGUAGE="JavaScript1.2" RUNAT="server">
function parse_str(input)
{
&nbsp;&nbsp;&nbsp;str = new string(input);
&nbsp;&nbsp;&nbsp;str = str.replace(/<zork>(.+?)<\/zork>/gi, "<a href=\"test.asp?name=$1\">$1</a>");
&nbsp;&nbsp;&nbsp;return str;
}
</SCRIPT>

The function from above will convert all occurencies of "<zork>BLAH</zork>" to appropriate links. Also, I suggest that you store non parsed text directly in database, so that you don't have to re-parse it back (I didn't write function for re-parsing).


InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 03-23-2002 22:46

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Smash
Bipolar (III) Inmate

From: Stockholm, Sweden
Insane since: Sep 2001

posted posted 03-24-2002 04:24

Sorry Ini but I have a tough time to see how I can manage to make a similar function to mr.maX's with that replace function.

If I could get an example I would be very glad!
I am not very good at regexps.

Thanks, Smash

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 03-24-2002 07:57

InI, replace() VB function doesn't except regular expressions and what Smash wants to do (he wants to implement some sort of UBB Code) should be done by using regular exspressions (didn't you notice that he wrote "<zork>ANYTHING</zork>" as match string and "<a href="test.asp?name=ANYTHING">ANYTHING</a>" as replace string).

Anyway, I also wrote VBScript version of my code from above. In order for it to work you must have MSIE5 and it's scripting engine installed on server (RegExp VBScript object is available starting from version 5):

<%

'Written by mr.maX, http://www.maxworld.co.yu/

Function parse_str(input)

Set maxRe = New RegExp

With maxRe
.Pattern = "<zork>(.+?)</zork>"
.IgnoreCase = True
.Global = True
End With

parse_str = maxRe.Replace(input, "<a href=""test.asp?name=$1"">$1</a>")
Set maxRe = nothing

End Function

%>


InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 03-24-2002 10:05

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 03-24-2002 10:21

That won't do what he wants...

Imagine that he has the following text:

---
You are responsible for obtaining access to the <zork>Service</zork> and that access may involve third party fees (such as <zork>Internet</zork> service provider or airtime charges). You are responsible for those <zork>Fees</zork>, including those fees associated with the display or delivery of <zork>Advertisements</zork>. In addition, you must provide and are responsible for all <zork>Equipment</zork> necessary to access the Service.
---

All occurencies of <zork></zork> tags should be matched ("ANYTHING" that he mentioned above, does really mean anything), and my function will parse that text, which will look like this afterwards:

---
You are responsible for obtaining access to the <a href="test.asp?name=Service">Service</a> and that access may involve third party fees (such as <a href="test.asp?name=Internet">Internet</a> service provider or airtime charges). You are responsible for those <a href="test.asp?name=Fees">Fees</a>, including those fees associated with the display or delivery of <a href="test.asp?name=Advertisements">Advertisements</a>. In addition, you must provide and are responsible for all <a href="test.asp?name=Equipment">Equipment</a> necessary to access the Service.
---

As I've said, he wants more or less the same behavior of &#91;URL] UBB Code tag...


« BackwardsOnwards »

Show Forum Drop Down Menu