Converting a list to tags on single line

I’m just getting started, with both AfO and Shortcuts. The first thing I’m building is a workflow to save links I want to share on my blog and elsewhere. When saving a link, I also want to decide on how to tag it. For this I currently use a muliti-select list, where I store the input to a variable:

But if I just put the Tags variable into the note I create, I get each selected tag on a separate line. What is the best way to iterate over the Chosen Item, adding a hashtag sign before each and removing the line-break at the end?


This would work:

  1. Set up a built-in Text action and have it hold the [Chosen Item].
  2. Add a Replace Text action, with the search term ^|\n (meaning “start of text block or new line”) and the replacement # (space + hash sign), and make it a regular expression.

1 Like

Excellent, thanks! So the ^ is matching the first item, and \n the following?

The Replace Text action takes the entire text as input and treats it as whole, not line by line. But regular expressions will replace matches, and the ^ matches not a character but a position: The very beginning of the input, i.e. the place before the first character. The \n are characters, namely the line breaks.