Hi,
Need help to write a really simple script that remove a underscore if its alone like “"
In total it adds up “name1” + "” + “name2” + “_” “name3” so that would be name1_name2_name3
but if one of the fields is empty it should not return underscores like name2 but just name2 or
just name1_name3 etc.
I’m a newbie and figured it out on airtable with the help of chatgpt but chatgpt dont understand baserow so i’m out of luck.
Baserow formulas are written in the open source Baserow Formula language which is a simple expression based language similar to formulas you will find in other spreadsheet tools.
In other words, it works similar to Airtable, Google Sheets or MS Excel formulas, but it has its own syntax.
I check your question again, and I think the easiest way to solve it is to divide your “problem” into smaller portions. In the screenshot below, the field ‘Remove right’ holds the final value. You can hide all the other fields. The test data ensures that all scenarios are tested.
Field 1 (Concat): Concatenate all fields with an underscore: concat(field('Title'),'_',field('Subtitle'),'_',field('Description'))
Field 2 (Regex): check for double underscores and replace them with a single one: regex_replace(field('Concat'), "__", "_")
Field 3 (Remove left): check if the first character is an underscore, and remove it if true: if(left(field('Regex'),1) = '_', right(field('Regex'), length(field('Regex')) - 1), field('Regex'))
Field 4 (Remove right): check if the last character is an underscore and remove it if true: if(right(field('Remove left'),1) = '_', left(field('Remove left'), length(field('Remove left')) - 1), field('Remove left'))
You can now hide (but not remove) fields 1 - 3. You can nest formulas if you want less columns, but dividing a problem into partial problems keeps your formulas more readable and easer to understand if you need to change them later.