Re: [NTG-context] getting path and filename from url
On 8/28/21 1:17 AM, Hans Hagen via ntg-context wrote: > On 8/27/2021 8:53 PM, Pablo Rodriguez via ntg-context wrote: >> [...] >> How can I get that match for #1 ends in the last slash (including it >> "../a/b/cb/ce.b/ca.b/c/") and match for #2 ends in the last period >> (excluding it, "dabc")? > it really helps to read the cld manual (or look into l-* files) as there > are plenty of efficient helpers for these things Many thanks for your reply, Hans. It really works like charm and reading cld-mkiv.pdf is one of the things I want to do in the near future. Many thanks for your help again, Pablo -- http://www.ousia.tk ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] getting path and filename from url
On 8/27/21 10:56 PM, Tomas Hala via ntg-context wrote: > Hi Pablo, > > is the following what you need? > > context("2a. " .. url:match "[^/]+/.+[.]") -- path and name with period > context("2c. " .. (url:match "[^/]+[^.]+$") :match ".+[.]") -- name with > period Hi Tomáš, well, I wnanted to remove the ending period in both cases (and to understand how that patterns might work. I got the first one with: context("2a ok. " .. url:match "[^/]+.+/") -- path and name But I’m stuck at the second one (sorry, I don’t know how to remove the final period): context("2c. " .. url:match "[^/]+.$":match("^.+%l+[.$]")) https://pragma-ade.com/general/manuals/cld-mkiv.pdf#search=nameonly is the way to go, but it won’t hurt me to understand how patterns might work here. Many thanks for your help, Pablo -- http://www.ousia.tk ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] getting path and filename from url
On 8/27/2021 8:53 PM, Pablo Rodriguez via ntg-context wrote: Dear list, I have the following sample: \starttext \startluacode url = "../a/b/cb/ce.b/ca.b/c/dabc.pdf" context(url) context("0 ok. " .. url:match "^(.*).pdf$") -- name and path context("1. " .. url:match "^(.*).+$") -- path context("2. " .. url:match"[^/]+[.$]") -- name context("3 ok. " .. url:match "[^.]+$") -- extension \stopluacode \stoptext How can I get that match for #1 ends in the last slash (including it "../a/b/cb/ce.b/ca.b/c/") and match for #2 ends in the last period (excluding it, "dabc")? it really helps to read the cld manual (or look into l-* files) as there are plenty of efficient helpers for these things local s = "./a/b/cb/ce.b/ca.b/c/dabc.pdf" print(file.pathpart(s)) print(file.nameonly(s)) print(file.basename(s)) print(file.suffix(s)) print(file.replacesuffix(s,"tmp")) - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] getting path and filename from url
Hi Pablo, is the following what you need? context("1. " .. url:match ".+/") context("2a. " .. url:match "[^/]+/.+[.]") -- path and name with period --context("2b. " .. url:match "[^/]+[^.]+$") -- name with period and extension context("2c. " .. (url:match "[^/]+[^.]+$") :match ".+[.]") -- name with period Best wishes, Tomáš Fri, Aug 27, 2021 ve 08:53:52PM +0200 Pablo Rodriguez via ntg-context napsal(a): # Dear list, # # I have the following sample: # # \starttext # \startluacode # url = "../a/b/cb/ce.b/ca.b/c/dabc.pdf" # # context(url) # # context("0 ok. " .. url:match "^(.*).pdf$") -- name and path # # context("1. " .. url:match "^(.*).+$") -- path # # context("2. " .. url:match"[^/]+[.$]") -- name # # context("3 ok. " .. url:match "[^.]+$") -- extension # \stopluacode # \stoptext # # How can I get that match for #1 ends in the last slash (including it # "../a/b/cb/ce.b/ca.b/c/") and match for #2 ends in the last period # (excluding it, "dabc")? # # Many thanks for your help, # # Pablo # -- # http://www.ousia.tk # ___ # If your question is of interest to others as well, please add an entry to the Wiki! # # maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context # webpage : http://www.pragma-ade.nl / http://context.aanhet.net # archive : https://bitbucket.org/phg/context-mirror/commits/ # wiki : http://contextgarden.net # ___ Tomáš Hála Mendelova univerzita, Provozně ekonomická fakulta, ústav informatiky Zemědělská 1, CZ-613 00 Brno, tel. +420 545 13 22 28 http://akela.mendelu.cz/~thala ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] getting path and filename from url
Dear list, I have the following sample: \starttext \startluacode url = "../a/b/cb/ce.b/ca.b/c/dabc.pdf" context(url) context("0 ok. " .. url:match "^(.*).pdf$") -- name and path context("1. " .. url:match "^(.*).+$") -- path context("2. " .. url:match"[^/]+[.$]") -- name context("3 ok. " .. url:match "[^.]+$") -- extension \stopluacode \stoptext How can I get that match for #1 ends in the last slash (including it "../a/b/cb/ce.b/ca.b/c/") and match for #2 ends in the last period (excluding it, "dabc")? Many thanks for your help, Pablo -- http://www.ousia.tk ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___