Skip to main content

Formula that replaces spaces with underscores and eliminates parentheses

  • July 1, 2022
  • 3 replies
  • 115 views

Forum|alt.badge.img+5

Hi Airtable community! I have a field in my table where I need a formula that outputs the name of a project Slack channel based on the name of the project. However, since Slack only allows for lowercase letters, underscores and dashes, the formula writing is a little complicated.

I need to convert all letters to lowercase, convert spaces to underscores, and not include anything that’s in parentheses.

For example, the project name is: FA22 Project Name / Project Detail (Project Subtitle)

And the output I need is: fa22_project_name_project_detail

Help is greatly appreciated!

3 replies

TheTimeSavingCo
Forum|alt.badge.img+31

Hi! The following formula should work if these two assumptions hold true:

  1. There’s only ever one set of parentheses
  2. If there is a set of parentheses, there is always a space in front of the “(”.
    • i.e. it will always be:
      • FA22 Project Name / Project Detail (Project Subtitle)
    • and will never be
      • FA22 Project Name / Project Detail(Project Subtitle)
LOWER(
  SUBSTITUTE(
    REPLACE(
      Name,
      FIND(" (", Name),
      FIND(")", Name),
      ""
    ),
    " ",
    "_"
  )
)

Forum|alt.badge.img+5
  • Author
  • New Participant
  • 4 replies
  • July 1, 2022

Thank you!

So - now realizing something. Not every project name necessarily has parentheses. So the formula worked on every project title WITH parentheses, but not on the ones without. Is there an IF formula that can be added?


TheTimeSavingCo
Forum|alt.badge.img+31

Thank you!

So - now realizing something. Not every project name necessarily has parentheses. So the formula worked on every project title WITH parentheses, but not on the ones without. Is there an IF formula that can be added?


Yeap!

LOWER(
  SUBSTITUTE(
    IF(
      FIND(" (", Name),
      REPLACE(
        Name,
        FIND(" (", Name),
        FIND(")", Name),
        ""
      ),
      Name
    )
    ,
    " ",
    "_"
  )
)