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

(https://www.ancestry.com/discoveryui-content/view/81296:7613?_phsrc=LgW7255&_phstart=successSource&gsln=rakes&ml_rpos=2&queryId=46e16cbbab2dbdef493d263f850766a6)

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

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

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)

3 Likes

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)

3 Likes

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 (*)."