Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Location
    India
    Posts
    109

    Unanswered: pattern replace in mysql

    hi all,
    is it possible to do a pattern replace in mysql ?
    say if i have a text like "Mozilla /4.0 (compatible others" , I would need to take off the "(compatible" part from that string and have the result displayed as "Mozilla /4.0 others" .

    I know that the pattern to search for is a text starting with "(" and ending with a space character but am not sure of how to do it.Can anyone help?

    Thanks,
    Celia

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you could always run an update query
    update tblLog set browseragent="Mozilla /4.0 others" where browser agent like "Mozilla /4.0%";

    I think the wild card in MySQL is % - need to check but away form the ref books at present

  3. #3
    Join Date
    Aug 2003
    Location
    India
    Posts
    109

    Re-pattern replace in mysql

    Sorry .. I think that I should have explained more ..
    The project that am involved with has got two tools .. one is a c++ file that does all the inserts and updates and the other one is a php that does only selects ..

    and am handling only the selects.. If I were able to do the updates, then i would have validated the field even before inserting the data.So am left with no choice than to filter the data before displaying.

    The data that is stored into the table has two information . One is the browser information and the other one is Operating System information..and because of this am getting all weird kind of data like

    Mozilla/4.0 WinNt
    Mozilla/4.0 (compatible Win98
    Mozilla/4.0 (Slurp others
    Mozilla/4.0 [en] (x11 x11
    Mozilla/4.0 others
    MSIE 6.0 winnt Win98

    These are just sample ones ... So I thought that the best way to get these two data displayed is to do a pattern replace like /\((.*?) /is ... .I can do this using php's preg_replace also but since am doing summary reports and I need to count the 3rd and 5th data as the same , it wud be better if i can do it in mysql. i heard that one can do rlike or regexp ... is it possible to combine this and replace() to accomplish the task?

    Thanks & Regards,
    Celia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •