At 02:54 PM 1/12/01 , Jerry Lake wrote:
>is it possible with regex to
>change one or more text characters
>followed by a space into the same
>characters followed by a tab?
>
>Jerry Lake


For example -

         $NewString = ereg_replace("([[:alpha:]]+) ", "\\1".chr(9), $String);

This will convert a sequence of one or more alphabetic characters followed 
by one space to the same set of characters followed by a tab (that's the 
chr(9) part).

If you want to match only a specific set of text characters - say, a, e, i, 
o and u - then you can use

         $NewString = eregi_replace("([aeiou]+) ", "\\1".chr(9), $String);

Notice i used eregi_replace() instead of ereg_replace(); the 'i' means case 
INsensitive.

Of course, there are other ways of doing this with preg_replace and 
str_replace, both of which are faster than ereg_replace (str_replace is the 
fastest); I happen to use ereg becaouse I'm most familiar with it, since it 
came along before the preg_ functions. As always, you can check out the docs:

         http://www.php.net/ereg_replace
         http://www.php.net/eregi_replace
         http://www.php.net/str_replace
         http://www.php.net/preg_replace


         -steve

(The usual off-the-top-of-my-head-untested-code-snippet caveats apply)



+------------------------------------------------------------------------+
| Steve Edberg                           University of California, Davis |
| [EMAIL PROTECTED]                                     (530)754-9127 |
| http://aesric.ucdavis.edu/                  http://pgfsun.ucdavis.edu/ |
+---------------------- Gort, Klaatu barada nikto! ----------------------+

Reply via email to