I have a regex I can't translate to km, please help

Here is the regex : https://regex101.com/r/Zzof5b/2

Here is what I typed in km :

This doesn't work. :frowning:

It’s an issue of the options.

See this wiki article for an explanation of how you specify regex options in KM.

Wow, this is confusing. Do I have to rewrite it to fit into the syntax offered by KM?

I actually got the regex from irc and similar to what you have done, I thought it would work since it is also using perl in regex101. I am not quite sure what options I need to change. Perhaps my substitution is wrong?

Thank you for any help.

Here is your regex101 page:

The big red arrow points to the regex options.

You need to specify those options in KM. You do it by adding the following to the front of the regex string:


You don't specify the "g" option, because KM always assumes that.

So, all you do is copy the expression from regex101, and add the flags to the front.

Here's what you end up with:


Confusing <=> Regular Expressions. It's par for the course.

1 Like

Ohh, this makes more sense now. Thank you.

Do I have to change the substitution in any way too because this doesn't work :

Use “$” instead of “”. Sorry that I didn’t notice that earlier.

Dollar-signs also work on regex101, so just start using them there, and then you don’t need to change anything.

1 Like

Wow, wow. This works. :yellow_heart:

If anyone wonders what this does, it take an url from google and transforms it to a search by ‘this week’ google query.

Thank you a lot Dan.

1 Like

Having fun yet? :slight_smile:

1 Like

Too much fun really. Karabiner + KM + Alfred is a godlike combination. Too much freedom and potential in there.

1 Like

It lets me do these crazy things with ease

Without Karabiner, these things would be unthinkable. Too much friction reaching for control key. Now my control key is a key and this changes everything.

If you say so. :slight_smile: As long as it works for you!

1 Like

Hey Dan,

If you have some spare second. Can you take a look at this regex please : https://regex101.com/r/h0gjsj/1

I did exactly as a above, specify options and swapping it into dollar signs but it does nothing. Gives me the same url.

Well, for one thing, you’re searching a variable called “url”, but you’re not using the variable afterwords.

1 Like

Relax, Dan, a working regex is pleasure enough, even without using it afterwards :wink:


LOL. Literally LOL.

Forgive my silliness. :frowning:

What about this? https://regex101.com/r/ShbtMy/1

I tried to translate it like so :

Did I make some mistake?

I don’t know - you’ll have to figure it out yourself. Sorry.

Perhaps someone else can take a look at this. I would really appreciate it. I mean it works perfectly in regex101 : https://regex101.com/r/ShbtMy/2

But in km, I don’t know why the same thing doesn’t work.

Also maybe my flag option is incorrect. From what Dan posted above, I suppose since this only uses g flag it should have (?) in the beginning. I tried with that and with nothing at all. Nothing works.

I also tried this : https://regex101.com/r/ShbtMy/5

Works well in browser, doesn’t work from KM. :frowning:

Hey Nikita,

You're making this overly complicated.

If you want someone to help you it's best to provide them with a turnkey macro for testing.

Something like this (which works by the way):

RegEx → String → Test KM Find & Replace RegEx.kmmacros (2.8 KB)

Provide absolutely clear before and after examples here in the forum that people can copy and paste to test in Keyboard Maestro, or BBEdit, or whatever regex test medium they want to use.

The easier you make it for us to test the problem you're having the more likely you're going to get useful help.