Ever struggled with exporting your Google Search Console keywords and converting them to the format required by URLs (dash-case)? Google sheets can help you with converting these keywords to the URL format.
Kevin Peters
—
6/3/2021
So let us start with explaining which tools we are going to use. Since this tutorial is focused on Google Sheets I assume you have a Google account with access to Google sheets. You can simply create a Google Drive account and should be set up then. Then simply create a new Google Spreadsheet.
Now we have to fill the spread sheet with data. For that we can use several data sources. Ideally you should use your own or even have data in your spreadsheet already. For an easy way to follow this tutorial simply copy the following list items and insert them into the spreadsheet:
So now we can actually work on the data. Now we will work on column B. Google Sheets supports the LOWER()
and UPPER()
functionality. These work kind of similar to what we want to achieve. Just that there need to be a function called DASH_CASE()
.
For this use case we need to extend Google Sheets though. This requires some programming but do not fear back. This article is written for everyone, even if you do not have any programming experience. Google supports something called the Script editor which we will open now. For that, go to the menu bar, click on Tools and then on Script Editor.
This should open a new tab. Do not scare back yet! The first thing you should do is to delete all the code in the script section so it looks like the following:
Now its time to code! Or as we say, just copy paste some snippets we have prepared for you. You can copy and paste the following code into the script window.
1function DASH_CASE(str) {
2 return str
3 .match(/[A-Z]{2,}(?=[A-Z][a-z0-9]*|\b)|[A-Z]?[a-z0-9]*|[A-Z]|[0-9]+/g)
4 .filter(Boolean)
5 .map(x => x.toLowerCase())
6 .join("-");
7}
8
The script window should look like the following then:
Now it is time to press the save icon on top of the code. Alternatively you can press CTRL + S (CMD + S on Mac) to save the script and then we can head back to the Google Sheet. Reload the page once. Ideally with CTRL + R (CMD + R on Mac). And select the field B1.
As with the LOWER()
function we can use the DASH_CASE()
function now. Simply type the following into the field B1: =DASH_CASE(A1)
And this results in the following value of the column: case-converter-extension
. So now we can also apply the function to all rows. You can do that by simply dragging the bottom right corner of field B1 to the bottom. You can also see it in the GIF below.
So this should have brought you to your goal. Feel free to share this article with your colleagues and if you have any feedback feel free to reach out to us.
Ever struggled to generate URL slugs from a long list of words in Google Sheets or Microsoft Excel? Not with our guide. Learn how to write a custom function to change the case style to dash-case, also known as kebab- or hyphen-case.
Kevin Peters
—
6/3/2021
Converting a string to camelCase in JavaScript (JS) can be quite tricky with all edge cases. This blog will show you how to handle the edge cases and even converting object keys.
Kevin Peters
—
5/6/2021
Changing the keys in objects in JavaScript objects is sometimes required. JavaScript mostly works with camelCase and transforming other case types is really helpful to make linters happy.
Kevin Peters
—
4/11/2021
For the hyphen-separated case there are multiple names: kebab-case, hyphen-case, slug-case and many other options... But what is the right one to choose. This article will help you to make a decision.
Kevin Peters
—
3/17/2021
The reasons why we love our technology stack at caseconverter.pro are quite diverse. Read it here and gather insightful statistics about which technologies were used and why you should use them too.
Kevin Peters
—
1/19/2020