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

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:

3 Likes

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.

-Chris

3 Likes

Hey Chris,

Yes, you are right. I should actually provide macros to make things easier and be more clear.

Your macro however doesn’t give the correct result.

The regex should for a string like this :

Should return this :

And for multiple word query url like this :

Should return this :

The macro you provided for a string like this :

Returns this :

https://github.com/search?utf8=✓&q=regex%20play&type=Repositories&ref=searchresults&o=desc&s=updated

Thank you for any help on this. I think the regexes above though give all the correct outputs : https://regex101.com/r/ShbtMy/2

Just not sure why in KM, it didn’t work for me. :frowning:

Chris’ regex gives me the same result as your regex on 101 (first test string).

However, I had to set the “Set Variable” action to “Process Nothing”:

Otherwise I get things like utf8=â.

Hey Tom,

I tried that too, it just gives me the %SafariURL% back, doesn't expand it.

Here is the full macro I am using :

###MACRO:   safari: main actions - e

~~~ VER: 1.0    2017-01-13 ~~~

####DOWNLOAD:
safari- main actions - e.kmmacros (39 KB)


###ReleaseNotes

TBD


You can try it too and see that it doesn't work by going to a page with a search like this one :

And pressing control + e. Ideally it should turn the search from 'best match' to 'most recently updated' but it doesn't do that. :disappointed:

Oh silly silly me. I was doing string matching all this time. Well this is embarrassing.

Thank you so much @DanThomas, @ccstone and @Tom. You are amazing.

1 Like

@nikivi, don't worry, this is a common mistake.
The more KM RegEx you personally create (and debug) the sooner stuff like this will come intuitively to you. This is one of the first things to check as part of the RegEx debug process.

Keep working with RegEx. There is always some trial-and-error involved, but more so in the beginning. :wink:

2 Likes

Not embarrassing, I think this is the most popular error with the Search and Replace action. I get trapped sometimes, too. Nasty thing it is.

LOL. So, here I was, reading along and thinking "Yeah, I make that mistake a lot too."

And then I got to thinking, "Wait a minute... I know a solution to that problem!" A minute or two later, and I now have a couple of Favorite Actions for doing regex search and replaces.

That thwack sound you heard was my hand hitting my forehead. :rolling_eyes: Why didn't I think of it before now? sigh

1 Like

2 posts were merged into an existing topic: UPDATED Sept. 20, 2016 v1.1 - MACRO: [KMFAM] Favorite Actions and Macros

It's sufficiently common that I hope to try to detect it in the future a put some sort of indication - it'll have to be unobtrusive enough to be un-anoying when it is intentional, but intrusive enough to get noticed.

3 Likes