sugan Posted July 16, 2007 Share Posted July 16, 2007 Hi,I have a table column which has alphanumeric values like "212as", "wd2232w"I want to replace all the values with the alpha characters removed.i.e 212as should be replaced as 212wd2232w should be replaced as 2232I tried using mysql convert function but in vain...Regards,Suganya Link to comment Share on other sites More sharing options...
vijay Posted July 16, 2007 Share Posted July 16, 2007 Hi.. For that retrive data via mysql query and process on it via regular expression /([a-zA-Z]+)([0-9]+)([a-zA-Z]+)/ - match this expression with that column preg_replace('([a-zA-Z]+)([0-9]+)([a-zA-Z]+)','\2','COLUMN_VALUE') with the help of above function use update query to replace with digits only.Regards,Vijay Link to comment Share on other sites More sharing options...
sugan Posted July 17, 2007 Author Share Posted July 17, 2007 Hi,To replace the values, do i want to use the PHP function preg_replace.Is there any function in mysql to replace those values?Regards,Suganya Link to comment Share on other sites More sharing options...
vijay Posted July 17, 2007 Share Posted July 17, 2007 Hi.. In mysql only function regexp only... there would be no function for direct replacement in mysql.. If is there any then let me know..Regards,Vijay Link to comment Share on other sites More sharing options...
Yahweh Posted July 17, 2007 Share Posted July 17, 2007 You're out of luck, Suganya, there's no function (at least not an elegant function) to remove alpha characters. You should probably do it programmatically. Hi.. For that retrive data via mysql query and process on it via regular expression /([a-zA-Z]+)([0-9]+)([a-zA-Z]+)/ - match this expression with that column preg_replace('([a-zA-Z]+)([0-9]+)([a-zA-Z]+)','\2','COLUMN_VALUE') with the help of above function use update query to replace with digits only.Regards,VijayThat expression is too complicated, and it doesn't match strings like "hello324234". You don't need to capture anything, just remove the unwanted characters:preg_replace('[^\d]', '', COLUMN_VALUE) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.