Solved How can I get part of the URL

I have a long url and I only need the part from the beginning to the ?

Sample URL: --


I have this regex (?<=http)(.*)(?=?) which works but I need to include the http

This solved it ^(.*)(?=?)

This would work too (http.+?\?)

Tho why tinker with regular expressions,
when Keyboard Maestro does this for you :slight_smile:

See the Filter with URL ... options of the Filter action

Screenshot 2023-06-17 at 15.47.08

Parts of URL extracted by .kmmacros (5.0 KB)


I guess I don't understand filter enough to make it work. And I am not very efficient with regex but eventually I can make it work.

Forgive me – I should have left the actions expanded in the image:

URL without query.kmmacros (3.6 KB)

1 Like

Tho a variable array index [1]? may be simpler:

manual:Variable Arrays [Keyboard Maestro Wiki]

URL without query II (array variable).kmmacros (2.7 KB)


I suspect the Forum has stripped a \ character in there -- it should be a "positive lookahead": ^(.*)(?=\?)

If you prefer a regex over Filters, this is perhaps easier to interpret:


"From the start of the string (^), match 'not a ?' ([^?]) as many times as possible (*)."