Horst Azeglio Posted January 8, 2007 Share Posted January 8, 2007 I'm trying to convert ever lowercase word "i" into an uppercase word I.Here's my code.[quote]$string="This is my string. i am a regular expression illiterate";$string=preg_replace("/[ \,\.!\?\']i[ \,\.!\?\']/","/[ \,\.!\?\']I[ \,\.!\?\']/",$string);[/quote] Link to comment https://forums.phpfreaks.com/topic/33382-solved-preg_replace-newbie-question-abour-regular-expressions/ Share on other sites More sharing options...
ted_chou12 Posted January 8, 2007 Share Posted January 8, 2007 if you are simply changing i to Ithen this:str_replace("i","I",$string);would workTed Link to comment https://forums.phpfreaks.com/topic/33382-solved-preg_replace-newbie-question-abour-regular-expressions/#findComment-155997 Share on other sites More sharing options...
Horst Azeglio Posted January 8, 2007 Author Share Posted January 8, 2007 I think it wouldn't work because it would also replace the i letter inside words.btwI just noticed the regex forum. I should have posted that topic in it. If a mod moves it I wont be confused. Link to comment https://forums.phpfreaks.com/topic/33382-solved-preg_replace-newbie-question-abour-regular-expressions/#findComment-155999 Share on other sites More sharing options...
effigy Posted January 8, 2007 Share Posted January 8, 2007 Try [tt]/\bi\b/[/tt]. Link to comment https://forums.phpfreaks.com/topic/33382-solved-preg_replace-newbie-question-abour-regular-expressions/#findComment-156010 Share on other sites More sharing options...
Horst Azeglio Posted January 8, 2007 Author Share Posted January 8, 2007 thanks a lot, super guru, it works perfectly, however, I don't understand the use of the backslash in that context. Can someone explain me why does it work? Link to comment https://forums.phpfreaks.com/topic/33382-solved-preg_replace-newbie-question-abour-regular-expressions/#findComment-156015 Share on other sites More sharing options...
effigy Posted January 8, 2007 Share Posted January 8, 2007 [url=http://regular-expressions.info/wordboundaries.html]Word Boundaries[/url] Link to comment https://forums.phpfreaks.com/topic/33382-solved-preg_replace-newbie-question-abour-regular-expressions/#findComment-156019 Share on other sites More sharing options...
Horst Azeglio Posted January 8, 2007 Author Share Posted January 8, 2007 thanks, I'm gonna read that Link to comment https://forums.phpfreaks.com/topic/33382-solved-preg_replace-newbie-question-abour-regular-expressions/#findComment-156022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.