Hey, heres where a perl coder like me could help you.
You would have to use a non-greedy quantifier.
However I believe IE's pathetic RegExp object doesnt support non-greedy
quantifiers like .*?
Thus you could use an alternative approach like shown below :
...
var contents = new String(" <script> bingo <\/script><script> tringo
<\/script>   <script> Bye <\/script> GoodBye <body>Done!<\/body> "); //for
example

var scripts = contents.split(/(\s*<script>|<\/script>\s*)/);
 alert(scripts[0]);
 alert(scripts[1]);
 alert(scripts[2]);
 alert(scripts[3]);
...

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Michael
Pemberton
Sent: Friday, February 09, 2001 10:20 AM
To: [EMAIL PROTECTED]
Subject: [Dynapi-Help] Regular Expressions


Does anyone now how I can achieve the following:
I want to parse the contents of a file and extract the <script> tags.
I'm currently using the following code:
    var scripts=/<script>\s*(.*)\s*<\/script>/i.exec(contents); // where
contents = file contents

If there is only one <script> tag everything works fine.  If there are
two, the result is stuffed.
e.g..
    var contents = "<script> alert('test 1') </script> test html
<script> alert('test 2') </script>";

scripts returns "alert('test 1') </script> test html <script>
alert('test 2')"

It should have returned and array of elements containing each of the
individual script tags code.

Any help would be greatly appreciated, thanx.

--
Michael Pemberton
[EMAIL PROTECTED]
ICQ: 12107010




_______________________________________________
Dynapi-Help mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-help


_______________________________________________
Dynapi-Help mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-help

Reply via email to