Jump to content

Recommended Posts

Perform a search and replace on copied text, and save regexs for future use.

 

Download:


 

Please visit http://code.instructorium.com/regex for more information.  (also on Packal: http://www.packal.org/workflow/regex )  A summary is below:

 

 

 

Commands you can use:

 

1. Any regular expression (no keyword necessary, Perl-style) "s/this/that/msg" "s@\$(\d+)\.(\d{2})@$1 dollars and $2 cents@g", etc.

 

regex1.png

 

2. Follow your regular expression with " save as " and then a name in order to save it for future use. "s&this&that&xg save as mythisthat", etc.

 

regex4.png

 

3. Use the "regex" keyword followed by the name you saved it under to execute a saved regex. "regex mythisthat", etc.

 

regex3.png

 

As far as I know, it works on all versions of Alfred 2 and all versions of OS X.  Your custom workflows are saved under ~/Library/Application Support/Alfred 2/workflows/com.verykiwi.regex/RegexSequences.pl.  You can delete the com.verykiwi.regex folder after uninstall.  Feel free to contact me if you have any issues.

Edited by Matthew Lancellotti

Share this post


Link to post

Version 1.5.0 is here.  Here are the improvements:

 

 

A checkmark appears on the icon when your regex is valid (correct syntax). Regex will not execute invalid regexs. It is…awesome.

 

You have full control to do custom regexing by opening the file at ~/Library/Application Support/Alfred 2/Workflow Data/com.verykiwi.com/RegexSequences.pl. Your custom regexs remain even when updating Regex.

Quoted regexs (sq) can be saved.

Share this post


Link to post

This is a very neat and novel idea!


 


Recently I’ve been trying to find a good way to do find-and-replace in Chrome, but I didn’t find the Chrome extensions to be very flexible, especially when I wanted to do find-and-replace on text selections.


 


I love this workflow because it’s like a one-size-fits-all: not only is it a good tool for Chrome, but it's also good for any Mac application since I can access Alfred from anywhere!  :D


 


I guess the only downside is that it requires the clipboard, but that isn’t a big deal for me since I have Alfred’s Clipboard History configured as well.


 


If I may suggest, would it be possible to support the tr/// operation as well?


 


Thanks so much!


Share this post


Link to post

Really great script!

How can I modify the script so that it works on the selected text in whatever app I have open?

 

@johnjoonso: Sorry I haven't checked this thread in so long.  You must COPY the text to your clipboard (typically via Edit > Copy or ⌘C) before running the workflow.

 

Then, when you type your regex and hit enter, the result is automatically pasted.

 

------

 

As a bonus, this means you could potentially copy text from one location, then move your cursor to another location, and get the result in the new location.

Share this post


Link to post

How to use this workflow ?

 

In Alfred 3, I tried   "regex tr/that/this"

 

It gives error: 

Could not open your RegexSequences.pl file.

 

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...