Skip to content

bigfunctions > remove_extra_whitespaces

remove_extra_whitespaces

Call or Deploy remove_extra_whitespaces ?

✅ You can call this remove_extra_whitespaces bigfunction directly from your Google Cloud Project (no install required).

  • This remove_extra_whitespaces function is deployed in bigfunctions GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error).
  • Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions. This is particularly useful if you want to create private functions (for example calling your internal APIs). Discover the framework

Public BigFunctions Datasets:

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...

Description

Signature

remove_extra_whitespaces(str)

Description

Remove unwanted whitespaces (inspired from re_data dbt repo)

Examples

select bigfunctions.eu.remove_extra_whitespaces('Hi   Madison  and Mateusz!\n How are you doing?')
select bigfunctions.us.remove_extra_whitespaces('Hi   Madison  and Mateusz!\n How are you doing?')
select bigfunctions.europe_west1.remove_extra_whitespaces('Hi   Madison  and Mateusz!\n How are you doing?')
+--------------------------------------------+
| cleaned_string                             |
+--------------------------------------------+
| Hi Madison and Mateusz! How are you doing? |
+--------------------------------------------+

Need help using remove_extra_whitespaces?

The community can help! Engage the conversation on Slack

For professional suppport, don't hesitate to chat with us.

Found a bug using remove_extra_whitespaces?

If the function does not work as expected, please

  • report a bug so that it can be improved.
  • or open the discussion with the community on Slack.

For professional suppport, don't hesitate to chat with us.

Use cases

You have a table of user-submitted comments where some users may have accidentally or intentionally added extra spaces within their text. This can affect analysis and presentation. You want to normalize the comments by removing extra spaces.

Example Table:

comment_id comment_text
1 " This is a comment . "
2 "Another comment."
3 " Yet another comment. "

Query using remove_extra_whitespaces:

SELECT
    comment_id,
    bigfunctions.us.remove_extra_whitespaces(comment_text) AS cleaned_comment_text
FROM
    `your_project.your_dataset.your_comments_table`;

Resulting Table:

comment_id cleaned_comment_text
1 "This is a comment ."
2 "Another comment."
3 "Yet another comment."

By using the remove_extra_whitespaces function, the extra spaces within the comments are removed, leaving only single spaces between words and removing leading/trailing spaces. This makes the comments cleaner and easier to analyze, search, and present. For example, if you were doing sentiment analysis or keyword extraction, removing the extra spaces would improve the accuracy of your results.

Spread the word

BigFunctions is fully open-source. Help make it a success by spreading the word!

Share on Add a on