sarathi Posted August 2, 2009 Share Posted August 2, 2009 I was wondering how I can replace a word, starting from a $ sign, until the first space after it? Link to comment https://forums.phpfreaks.com/topic/168450-solved-preg_replace-until-space/ Share on other sites More sharing options...
Garethp Posted August 2, 2009 Share Posted August 2, 2009 Use this pattern '/\$(.*?)\s$/'; Here's something for some reading up http://www.regular-expressions.info/anchors.html The $ normally signifies the end of a string, so you have to escape it when you want to use it as an alphanumeric character Link to comment https://forums.phpfreaks.com/topic/168450-solved-preg_replace-until-space/#findComment-888584 Share on other sites More sharing options...
sarathi Posted August 2, 2009 Author Share Posted August 2, 2009 Thank you for your help, I changed the code a bit to fit my needs: '~\$([a-z]*?)(?![a-z])~' But I'm wondering how I can add a-z and 0-9? Link to comment https://forums.phpfreaks.com/topic/168450-solved-preg_replace-until-space/#findComment-888587 Share on other sites More sharing options...
Garethp Posted August 2, 2009 Share Posted August 2, 2009 Instead of [a-z] use [a-zA-Z0-9]. That matches Lowercase, Uppercare and Numerals Link to comment https://forums.phpfreaks.com/topic/168450-solved-preg_replace-until-space/#findComment-888649 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.