Re: Cannot even come up with the beginning of a regex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2008. 02. 27, szerda keltezéssel 12.46-kor Dotan Cohen ezt írta:
> Hi all, it's been a while since I've written with a regex problem.
> This time, I'm stumped.
> 
> I've got some text that needs to have five letters, if found not at
> the end of a word, to be replaced with different letters. For
> instance, should the letter "a" be found at the end of a word, leave
> it alone. Should the letter "a" be found anywhere else in the word
> (beginning, middle, or by itself) then change it into "A". Sound
> frustrating? It is, at least to me. Can someone help out?

echo preg_replace('/\b[^\s]+a\b.*/U', 'A', 'whatever i want that hasa a
on the end');

if you want to replace standalone 'a'-s too, change the pattern to
'/\b[^\s]*a\b.*/U'

look up the meaning of \b here, that's what you missed I think:
http://hu.php.net/manual/en/reference.pcre.pattern.syntax.php

and also the meaning of the U modifier here:
http://hu.php.net/manual/en/reference.pcre.pattern.modifiers.php

greets
Zoltán Németh

> 
> For those who want more details for curiosity's sake, I'm writing a
> Hebrew transliteration engine for the gibberish.co.il website. This
> function will handle the Final Letter situations.
> 
> Thanks in advance.
> 
> Dotan Cohen
> 
> http://what-is-what.com
> http://gibberish.co.il
 <א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
> 
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux