playaz Posted May 15, 2009 Share Posted May 15, 2009 Hi guys, I am a total newbie at regex - I require an expression that will remove all letters from a string eg.. Below is an example of original string, and the result I would need in the $newString variable - what expression would be required to do this? $string = '472PP'; $newString = '472'; Thanks again! Link to comment https://forums.phpfreaks.com/topic/158253-expression-to-return-numbers-only/ Share on other sites More sharing options...
Adam Posted May 15, 2009 Share Posted May 15, 2009 With regex you could do it like this: $number = preg_replace('/[^0-9]*/', '', $str); Link to comment https://forums.phpfreaks.com/topic/158253-expression-to-return-numbers-only/#findComment-834674 Share on other sites More sharing options...
playaz Posted May 15, 2009 Author Share Posted May 15, 2009 Thanks Adam!! thats superb :-) Link to comment https://forums.phpfreaks.com/topic/158253-expression-to-return-numbers-only/#findComment-834683 Share on other sites More sharing options...
.josh Posted May 15, 2009 Share Posted May 15, 2009 you don't technically need that * in there. Link to comment https://forums.phpfreaks.com/topic/158253-expression-to-return-numbers-only/#findComment-834707 Share on other sites More sharing options...
Adam Posted May 18, 2009 Share Posted May 18, 2009 Ha yerrrr I know! Just like the stars! Link to comment https://forums.phpfreaks.com/topic/158253-expression-to-return-numbers-only/#findComment-836263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.