Re: [PHP] regular expression for (NOT 'word')

2002-03-16 Thread scott furt

Try this... it should only print out "Some webpage data"

$text = "
script data.
Some webpage data
another script data 
";

print preg_replace('/(.*?)<\/script>/',
   '', $text);


Ando Saabas wrote:
> Ok let me explain my problem further some. I need the regular expression to
> purify the html page from script tags:
> I used: $file = eregi_replace("(.*)", " ", $file);
> Now this works fine, until theres a webpage like:
> 
> script data.
> Some webpage data
> another script data 
> 
> so the regexp above replaces everything between first  and last
>  ie the webpage data also.
> So i thought to change the regexp to something like this:  $file =
> eregi_replace("(NOT(script))", " ", $file);
> where NOT(script) would match everything that contains word script
> 
> 
> 
> 
> Rick Emery wrote:
> 
> 
>>the best you can do is:
>>
>>>$a = "this has php  in the string";
>>if( ! ereg("php", $a ) )
>>{ print "a: not in string"; }
>>$a = "this has in the string";
>>if( ! ereg("php", $a ) )
>>{ print "b: not in string"; }
>>?>
>>
>>-Original Message-
>>From: Ando Saabas [mailto:[EMAIL PROTECTED]]
>>Sent: Thursday, March 14, 2002 9:33 AM
>>To: [EMAIL PROTECTED]
>>Subject: [PHP] regular expression for (NOT 'word')
>>
>>how would i build a regular expression in php that would match
>>everything but the given word. For example, match the string only if
>>there isnt a word 'php' in the string.
>>I understand i can list characters i dont want to see in the string:
>>[^php].
>>but this means there cant be any p or h in the string. And ^(php) checks
>>if the string starts with 'php'.
>>How should i do it?
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>>
> 
> 




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] regular expression for (NOT 'word')

2002-03-14 Thread Michael Sims

At 05:52 PM 3/14/2002 +0200, Ando Saabas wrote:
>Ok let me explain my problem further some. I need the regular expression to
>purify the html page from script tags:
>I used: $file = eregi_replace("(.*)", " ", $file);
>Now this works fine, until theres a webpage like:
>
>script data.
>Some webpage data
>another script data 
>
>so the regexp above replaces everything between first  and last
> ie the webpage data also.
>So i thought to change the regexp to something like this:  $file =
>eregi_replace("(NOT(script))", " ", $file);
>where NOT(script) would match everything that contains word script

I suspect that POSIX extended regular expression functions will not be 
sufficient to do what you want.  Most likely you will need to use the PRCE 
functions (preg_replace, etc.)  I tried to come up with a regex to do what 
you are looking for but it's beyond me.  I think it may have something to 
do with what is called a "negative look ahead assertion", although I 
couldn't personally get it to work.  You can read about negative look ahead 
assertions here:

http://www.perldoc.com/perl5.6.1/pod/perlre.html

You may be better off asking this question on a Perl newsgroup or mailing 
list...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] regular expression for (NOT 'word')

2002-03-14 Thread Ando Saabas

Ok let me explain my problem further some. I need the regular expression to
purify the html page from script tags:
I used: $file = eregi_replace("(.*)", " ", $file);
Now this works fine, until theres a webpage like:

script data.
Some webpage data
another script data 

so the regexp above replaces everything between first  and last
 ie the webpage data also.
So i thought to change the regexp to something like this:  $file =
eregi_replace("(NOT(script))", " ", $file);
where NOT(script) would match everything that contains word script




Rick Emery wrote:

> the best you can do is:
>
>  $a = "this has php  in the string";
> if( ! ereg("php", $a ) )
> { print "a: not in string"; }
> $a = "this has in the string";
> if( ! ereg("php", $a ) )
> { print "b: not in string"; }
> ?>
>
> -Original Message-
> From: Ando Saabas [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, March 14, 2002 9:33 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] regular expression for (NOT 'word')
>
> how would i build a regular expression in php that would match
> everything but the given word. For example, match the string only if
> there isnt a word 'php' in the string.
> I understand i can list characters i dont want to see in the string:
> [^php].
> but this means there cant be any p or h in the string. And ^(php) checks
> if the string starts with 'php'.
> How should i do it?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] regular expression for (NOT 'word')

2002-03-14 Thread Rick Emery

the best you can do is:



-Original Message-
From: Ando Saabas [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 14, 2002 9:33 AM
To: [EMAIL PROTECTED]
Subject: [PHP] regular expression for (NOT 'word')


how would i build a regular expression in php that would match
everything but the given word. For example, match the string only if
there isnt a word 'php' in the string.
I understand i can list characters i dont want to see in the string:
[^php].
but this means there cant be any p or h in the string. And ^(php) checks
if the string starts with 'php'.
How should i do it?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php