Use regex to match and replace in MySql 8.0+ or MariaDB

UPDATE server_list_server
  SET world_id=regexp_replace(ip,'wg(\\d+)\.glwsy\.szgla\.com;?','\\1')
  WHERE ip REGEXP 'wg(\\d+)\.glwsy\.szgla\.com;?'
    AND world_id!=regexp_replace(ip,'wg(\\d+)\.glwsy\.szgla\.com;?','\\1');
  • REGEXP
  • regexp_replace
  • \\1 is the placeholder for matched group

Leave a Comment