Jump to content
Bottacco

Substitute Tab character with Return

Recommended Posts

I am trying to create a simple workflow to copy a selected row in Excel and place it on the clipboard after changing the tab character that separates fields in a return character. I am trying to use a conversion with regex of \t to \n but it is not working. Any ideas?

Share this post


Link to post

Hi @Bottacco, welcome to the forum.

 

For some reason, Alfred doesn't understand \n and the like in its Replace utility. You'll have to use a Run Script instead. This is Python:

import sys
sys.stdout.write(sys.argv[1].replace('\t', '\n'))

 

Share this post


Link to post

Thank you very much for your help @deanishe. I have found an old comment by @Andrew stating that Alfred uses NSRegularExpression for regex search and replace and that \n in the substitution field is not recognized because the \ character is taken as a literal. The solution offered by @Andrew is to use Alt+Return instead. I have tried it and it works, but now there is a second problem: once you input Alt+Return in the substitution field there is no way to delete it because it doesn't appear in the field, so I had to delete that element in the workflow and recreate it.

 

The post where Andrew talks about it is here:

 

 

Share this post


Link to post
8 hours ago, Bottacco said:

there is no way to delete it because it doesn't appear in the field, so I had to delete that element in the workflow and recreate it.

 

Doesn't ⌘A and ⌫ work?

Share this post


Link to post

You are right. It didn't occur to me to use ⌘A on an empty field.

 

Thank you very much for your help, but I hope that the behavior with regex with normal things like \t and \n becomes standard.

 

Cheers

Edited by Bottacco

Share this post


Link to post
2 hours ago, Bottacco said:

It didn't occur to me to use ⌘A on an empty field

 

The field's not empty. Newlines are invisible.

 

2 hours ago, Bottacco said:

I hope that the behavior with regex with normal things like \t and \n becomes standard

 

Yeah. That's pretty much how they work everywhere else, and it's surprising and somewhat frustrating that Alfred doesn't understand things like \n.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...