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

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