SQL: Regex Replace

You are given a table named repositories, format as below:

** repositories table schema **

  • project
  • commits
  • contributors
  • address

The table shows project names of major cryptocurrencies, their numbers of commits and contributors and also a random donation address ( not linked in any way :) ).

Your job is to remove all numbers in the address column and replace with ‘!’, then return a table in the following format:

** output table schema **

  • project
  • commits
  • contributors
  • address

Case should be maintained.

Hint: Use regexp_replace function, and the ‘g’ instructs that replace ALL the occurances

Solution:

SELECT project, commits, contributors, 
reg_exp.replace(address, '[0-9]','!','g') as address
FROM repositories;

Link

Reference

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store