Re: [PHP] Regex function needed

2002-02-08 Thread Michael Kimsal

Bas Jobsen wrote:
> Op donderdag 07 februari 2002 23:58, schreef Michael Kimsal:
> 
>>Looking for a regex (preg or ereg) to remove
>>all 1, 2 and 3 character words.
>>
> 
>  $string="over deze regex loop ik nu al de hele dag en een uur te piekeren. 't 
> wil niet! of wel! l'a.";
> $string=" ".$string;
> while (preg_match("/\W\w{1,3}\W/i",$string))
> $string = preg_replace("/\W\w{1,3}\W/i", " ", $string); 
> $string=substr($string,1);
> echo $string;
> ?>
> 



This looks like it should do the trick - thank you.

And thanks to everyone else who replied as well!



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




RE: [PHP] Regex function needed

2002-02-07 Thread Martin Towell

what about?

$str = "a bc def ghij klmno p qr i'd do, it. stu vwxy a";
$az = "[a-zA-Z']";
$str = str_replace(",", " , ", $str);
$str = str_replace(".", " . ", $str);
$str = trim(preg_replace(array("/ $az /", "/ $az$az /", "/ $az$az$az /"), "
", " $str "));  // couldn't get "/ [a-zA-Z]{1,3} /" to work :(
$str = str_replace("  ", " ", $str);
$str = str_replace(" ,", ",", $str);
$str = str_replace(" .", ".", $str);
$str = str_replace(",.", ".", $str);

echo $str;

-Original Message-
From: Douglas Maclaine-cross [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 08, 2002 11:09 AM
To: 'Edward van Bilderbeek - Bean IT'; Michael Kimsal;
[EMAIL PROTECTED]
Subject: RE: [PHP] Regex function needed


I don't know about preg but how about this monster?

$str = "I'm okay now aren't I. Do I work? 'mm";

while(eregi(' [a-z\']{1,3} ', $str)) 
$str = eregi_replace(' [a-z\']{1,3} ', ' ', $str);

while(eregi(' [a-z\']{1,3}([^a-z\' ])', $str)) 
$str = eregi_replace(' [a-z\']{1,3}([^a-z\' ])', '\1', $str);

while(eregi('([^a-z\' ])[a-z\']{1,3} ', $str)) 
$str = eregi_replace('([^a-z\' ])[a-z\']{1,3} ', '\1', $str);

$str = eregi_replace('^[a-z\']{1,3} ', '', $str);
$str = eregi_replace('^[a-z\']{1,3}([^a-z\'])', '\1', $str);

$str = eregi_replace(' [a-z\']{1,3}$', '', $str);
$str = eregi_replace('([^a-z\' ])[a-z\']{1,3}$', '\1', $str);

echo $str;

-Original Message-
From: Edward van Bilderbeek - Bean IT [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 08, 2002 11:09
To: Michael Kimsal; [EMAIL PROTECTED]
Subject: Re: [PHP] Regex function needed


after some puzzling I came to this:

$str = "One as a start. This is or was a test for short words, although an,
should be deleted to.";

$str = preg_replace(array("/\b[A-Za-z']{1,3}\b/",
"/[ ]{1}([ ]{1}|[,]{1}|[.]{1}|[:]{1})/"), array("", "\\1"), $str);

print $str;




which means:
first: replace all 1,2 or 3 character occurrences by nothing after that,
replace all spaces that are followed by one comma, or one period, or one :
by that comma, period or :

hope this is what you wanted?

Edward


- Original Message -
From: "Bas Jobsen" <[EMAIL PROTECTED]>
To: "Michael Kimsal" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Friday, February 08, 2002 1:10 AM
Subject: Re: [PHP] Regex function needed


> Op donderdag 07 februari 2002 23:58, schreef Michael Kimsal:
> > Looking for a regex (preg or ereg) to remove
> > all 1, 2 and 3 character words.
>
>  $string="over deze regex loop ik nu al de hele dag en een uur te piekeren.
't
> wil niet! of wel! l'a.";
> $string=" ".$string;
> while (preg_match("/\W\w{1,3}\W/i",$string))
> $string = preg_replace("/\W\w{1,3}\W/i", " ", $string);
> $string=substr($string,1);
> echo $string;
> ?>
>
> --
> 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] Regex function needed

2002-02-07 Thread Douglas Maclaine-cross

I don't know about preg but how about this monster?

$str = "I'm okay now aren't I. Do I work? 'mm";

while(eregi(' [a-z\']{1,3} ', $str)) 
$str = eregi_replace(' [a-z\']{1,3} ', ' ', $str);

while(eregi(' [a-z\']{1,3}([^a-z\' ])', $str)) 
$str = eregi_replace(' [a-z\']{1,3}([^a-z\' ])', '\1', $str);

while(eregi('([^a-z\' ])[a-z\']{1,3} ', $str)) 
$str = eregi_replace('([^a-z\' ])[a-z\']{1,3} ', '\1', $str);

$str = eregi_replace('^[a-z\']{1,3} ', '', $str);
$str = eregi_replace('^[a-z\']{1,3}([^a-z\'])', '\1', $str);

$str = eregi_replace(' [a-z\']{1,3}$', '', $str);
$str = eregi_replace('([^a-z\' ])[a-z\']{1,3}$', '\1', $str);

echo $str;

-Original Message-
From: Edward van Bilderbeek - Bean IT [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 08, 2002 11:09
To: Michael Kimsal; [EMAIL PROTECTED]
Subject: Re: [PHP] Regex function needed


after some puzzling I came to this:

$str = "One as a start. This is or was a test for short words, although an,
should be deleted to.";

$str = preg_replace(array("/\b[A-Za-z']{1,3}\b/",
"/[ ]{1}([ ]{1}|[,]{1}|[.]{1}|[:]{1})/"), array("", "\\1"), $str);

print $str;




which means:
first: replace all 1,2 or 3 character occurrences by nothing after that,
replace all spaces that are followed by one comma, or one period, or one :
by that comma, period or :

hope this is what you wanted?

Edward


- Original Message -
From: "Bas Jobsen" <[EMAIL PROTECTED]>
To: "Michael Kimsal" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Friday, February 08, 2002 1:10 AM
Subject: Re: [PHP] Regex function needed


> Op donderdag 07 februari 2002 23:58, schreef Michael Kimsal:
> > Looking for a regex (preg or ereg) to remove
> > all 1, 2 and 3 character words.
>
>  $string="over deze regex loop ik nu al de hele dag en een uur te piekeren.
't
> wil niet! of wel! l'a.";
> $string=" ".$string;
> while (preg_match("/\W\w{1,3}\W/i",$string))
> $string = preg_replace("/\W\w{1,3}\W/i", " ", $string);
> $string=substr($string,1);
> echo $string;
> ?>
>
> --
> 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] Regex function needed

2002-02-07 Thread Edward van Bilderbeek - Bean IT

after some puzzling I came to this:

$str = "One as a start. This is or was a test for short words, although an,
should be deleted to.";

$str = preg_replace(array("/\b[A-Za-z']{1,3}\b/",
"/[ ]{1}([ ]{1}|[,]{1}|[.]{1}|[:]{1})/"), array("", "\\1"), $str);

print $str;




which means:
first: replace all 1,2 or 3 character occurrences by nothing after that,
replace all spaces that are followed by one comma, or one period, or one :
by that comma, period or :

hope this is what you wanted?

Edward


- Original Message -
From: "Bas Jobsen" <[EMAIL PROTECTED]>
To: "Michael Kimsal" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Friday, February 08, 2002 1:10 AM
Subject: Re: [PHP] Regex function needed


> Op donderdag 07 februari 2002 23:58, schreef Michael Kimsal:
> > Looking for a regex (preg or ereg) to remove
> > all 1, 2 and 3 character words.
>
>  $string="over deze regex loop ik nu al de hele dag en een uur te piekeren.
't
> wil niet! of wel! l'a.";
> $string=" ".$string;
> while (preg_match("/\W\w{1,3}\W/i",$string))
> $string = preg_replace("/\W\w{1,3}\W/i", " ", $string);
> $string=substr($string,1);
> echo $string;
> ?>
>
> --
> 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] Regex function needed

2002-02-07 Thread Bas Jobsen

Op donderdag 07 februari 2002 23:58, schreef Michael Kimsal:
> Looking for a regex (preg or ereg) to remove
> all 1, 2 and 3 character words.



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




RE: [PHP] Regex function needed

2002-02-07 Thread Martin Towell

what about words at the start of the string??
eg
$str = "One can see this is or was a test for short words, although an,
should be deleted to.";

-Original Message-
From: Edward van Bilderbeek - Bean IT [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 08, 2002 10:47 AM
To: [EMAIL PROTECTED]; Michael Kimsal
Subject: Re: [PHP] Regex function needed


this might even work beter, to take comma's and periods etecetera into
account to:

$str = "This is or was a test for short words, although an, should be
deleted to.";

while (ereg(" [a-z]{1,3} ", $str)) {
 $str = eregi_replace(" [a-z']{1,3}([ ]{1}|[,]{1}|[.]{1}|[:]{1})", "\\1",
$str);
}


or even this for comma's etcetera before the words:

$str = "This is or was a test for short words, although an, should be
deleted to.";

while (ereg(" [a-z]{1,3} ", $str)) {
 $str =
eregi_replace("([ ]{1}|[,]{1}|[.]{1}|[:]{1})[a-z']{1,3}([ ]{1}|[,]{1}|[.]{1}
|[:]{1})", "\\2", $str);
}



Greets,

Edward


print $str;
- Original Message -
From: "Edward van Bilderbeek - Bean IT" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; "Michael Kimsal" <[EMAIL PROTECTED]>
Sent: Friday, February 08, 2002 12:33 AM
Subject: Re: [PHP] Regex function needed


> I don't know if this is the best way but:
>
> $str = "This is or was a test for short words";
>
> while (ereg(" [a-z]{1,3} ", $str)) {
>  $str = eregi_replace(" [a-z]{1,3} ", " ", $str);
> }
> print $str;
>
>
> this replaces all occurences of a space followed by 1,2 or 3 alphabetic
> characters followed by a space... the reason why it's performed in a while
> loop is because of two or more short words following each other and thus
> sharing a space...
>
>
> Greets,
>
> Edward
>
>
>
> - Original Message -
> From: "Michael Kimsal" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, February 07, 2002 11:58 PM
> Subject: [PHP] Regex function needed
>
>
> > Looking for a regex (preg or ereg) to remove
> > all 1, 2 and 3 character words.
> >
> >
> > --
> > 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
>



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



Re: [PHP] Regex function needed

2002-02-07 Thread Edward van Bilderbeek - Bean IT

this might even work beter, to take comma's and periods etecetera into
account to:

$str = "This is or was a test for short words, although an, should be
deleted to.";

while (ereg(" [a-z]{1,3} ", $str)) {
 $str = eregi_replace(" [a-z']{1,3}([ ]{1}|[,]{1}|[.]{1}|[:]{1})", "\\1",
$str);
}


or even this for comma's etcetera before the words:

$str = "This is or was a test for short words, although an, should be
deleted to.";

while (ereg(" [a-z]{1,3} ", $str)) {
 $str =
eregi_replace("([ ]{1}|[,]{1}|[.]{1}|[:]{1})[a-z']{1,3}([ ]{1}|[,]{1}|[.]{1}
|[:]{1})", "\\2", $str);
}



Greets,

Edward


print $str;
- Original Message -
From: "Edward van Bilderbeek - Bean IT" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; "Michael Kimsal" <[EMAIL PROTECTED]>
Sent: Friday, February 08, 2002 12:33 AM
Subject: Re: [PHP] Regex function needed


> I don't know if this is the best way but:
>
> $str = "This is or was a test for short words";
>
> while (ereg(" [a-z]{1,3} ", $str)) {
>  $str = eregi_replace(" [a-z]{1,3} ", " ", $str);
> }
> print $str;
>
>
> this replaces all occurences of a space followed by 1,2 or 3 alphabetic
> characters followed by a space... the reason why it's performed in a while
> loop is because of two or more short words following each other and thus
> sharing a space...
>
>
> Greets,
>
> Edward
>
>
>
> - Original Message -
> From: "Michael Kimsal" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, February 07, 2002 11:58 PM
> Subject: [PHP] Regex function needed
>
>
> > Looking for a regex (preg or ereg) to remove
> > all 1, 2 and 3 character words.
> >
> >
> > --
> > 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
>



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




Re: [PHP] Regex function needed

2002-02-07 Thread Edward van Bilderbeek - Bean IT

I don't know if this is the best way but:

$str = "This is or was a test for short words";

while (ereg(" [a-z]{1,3} ", $str)) {
 $str = eregi_replace(" [a-z]{1,3} ", " ", $str);
}
print $str;


this replaces all occurences of a space followed by 1,2 or 3 alphabetic
characters followed by a space... the reason why it's performed in a while
loop is because of two or more short words following each other and thus
sharing a space...


Greets,

Edward



- Original Message -
From: "Michael Kimsal" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, February 07, 2002 11:58 PM
Subject: [PHP] Regex function needed


> Looking for a regex (preg or ereg) to remove
> all 1, 2 and 3 character words.
>
>
> --
> 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] Regex function needed

2002-02-07 Thread Douglas Maclaine-cross

$string = ereg_replace("[A-Za-z']{1,3}", "", $string); // don't forget "I'm"

I haven't checked but something like this.


-Original Message-
From: Michael Kimsal [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 08, 2002 9:59
To: [EMAIL PROTECTED]
Subject: [PHP] Regex function needed


Looking for a regex (preg or ereg) to remove
all 1, 2 and 3 character words.


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