etrader Posted January 24, 2011 Share Posted January 24, 2011 I have a string with the structure of "word(11), word2(43), word3(99)". I want to delete the number between parenthesis to get "word, word2, word3"; but there's something wrong with this: $words = preg_replace("/(0-9)/", "", $words); Link to comment https://forums.phpfreaks.com/topic/225508-deleting-numbers-between-parenthesis/ Share on other sites More sharing options...
Psycho Posted January 24, 2011 Share Posted January 24, 2011 One reason is because parens have special significance within regular expressions and that code is not interpreting those parens as parens. You will need to escape them. $words = preg_replace("/\([0-9]+\)/", "", $words); Link to comment https://forums.phpfreaks.com/topic/225508-deleting-numbers-between-parenthesis/#findComment-1164468 Share on other sites More sharing options...
Roman Fedorov Posted January 24, 2011 Share Posted January 24, 2011 Hi, the pattern you wrote will search exactly the string "0-9", if you wanted to specify digits from 0 to 9 you should write "[0-9]" Anyway in your case try with $words = preg_replace("/\\(\\d.\\)/", "", $words); Link to comment https://forums.phpfreaks.com/topic/225508-deleting-numbers-between-parenthesis/#findComment-1164470 Share on other sites More sharing options...
etrader Posted January 24, 2011 Author Share Posted January 24, 2011 Thanks for the effective solutions and useful guides Link to comment https://forums.phpfreaks.com/topic/225508-deleting-numbers-between-parenthesis/#findComment-1164475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.