Jump to content

applying Regular Expressions to a query


Recommended Posts

Posted

Can I apply regular expressions to a query before passing it on?

 

For example, instead of "tel:{query}"

 

I want to do something more like "tel:{query} s/\(([0-9]{3})\) ([0-9]{3})-([0-9]{4})/\1\2\3"

 

which would effectively strip the telephone number of its parenthesis and dash.

 

Thanks!

 

(P.S., if not possible directly in URI/URL scheme, how to do it with Applescript or Javascript or Ruby or some language?)

(P.P.S. in Alfred it says "URL scheme" but elsewhere I see "URI scheme" online)

Posted

Can I apply regular expressions to a query before passing it on?

 

For example, instead of "tel:{query}"

 

I want to do something more like "tel:{query} s/\(([0-9]{3})\) ([0-9]{3})-([0-9]{4})/\1\2\3"

 

which would effectively strip the telephone number of its parenthesis and dash.

 

Thanks!

 

(P.S., if not possible directly in URI/URL scheme, how to do it with Applescript or Javascript or Ruby or some language?)

(P.P.S. in Alfred it says "URL scheme" but elsewhere I see "URI scheme" online)

 

Anything you can do in terminal, or via script can be done in Alfred, so yes. You may have to pass it through a script first, but most of it is usually possible one way or another

Posted

Alfred will not handle regular expressions for you. However, you can easily accomplish this using a script.

 

In Python, to remove all non-numeric characters (using regular expressions):

import re
formatted = re.sub(r'[^\d]+', '', '{query}')

Code originally from Stack Overflow

Posted

Thanks this is what I was looking for!!!  Okay so now my python script says

import re
import os

formatted = re.sub(r'[^\d]+', '', '{query}')
os.system("open tel:"+formatted)

and it works.  Thanks for the help.

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