Jump to content

Regex - Run and save regular expressions!

Recommended Posts

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




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.




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.




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




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
Link to comment
  • 2 weeks later...

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.

Link to comment

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!

Link to comment
  • 2 months later...
  • 11 months later...

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.

Link to comment
  • 2 years later...
  • 4 years later...

[22:21:14.156] Logging Started...

[22:37:16.866] Logging Stopped.

[22:40:08.978] Logging Started...

[22:40:13.799] Regex[Script Filter] Queuing argument ' tr/that/this'

[22:40:13.841] Regex[Script Filter] Script with argv '(null)' finished

[22:40:13.844] ERROR: Regex[Script Filter] Code 2: Can't locate VeryKiwiHelpers.pm in @INC (you may need to install the VeryKiwiHelpers module) (@INC contains: /Library/Perl/5.30/darwin-thread-multi-2level /Library/Perl/5.30 /Network/Library/Perl/5.30/darwin-thread-multi-2level /Network/Library/Perl/5.30 /Library/Perl/Updates/5.30.3 /System/Library/Perl/5.30/darwin-thread-multi-2level /System/Library/Perl/5.30 /System/Library/Perl/Extras/5.30/darwin-thread-multi-2level /System/Library/Perl/Extras/5.30) at -e line 1.

BEGIN failed--compilation aborted at -e line 1.


Tried to use this regex workflow -- but getting above error message. Can somebody help in resolving this? or suggest alternative

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...