* getting path and filename from url
@ 2021-08-27 18:53 Pablo Rodriguez via ntg-context
2021-08-27 20:56 ` Tomas Hala via ntg-context
2021-08-27 23:17 ` Hans Hagen via ntg-context
0 siblings, 2 replies; 5+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2021-08-27 18:53 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Pablo Rodriguez
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: getting path and filename from url
2021-08-27 18:53 getting path and filename from url Pablo Rodriguez via ntg-context
@ 2021-08-27 20:56 ` Tomas Hala via ntg-context
2021-08-28 9:18 ` Pablo Rodriguez via ntg-context
2021-08-27 23:17 ` Hans Hagen via ntg-context
1 sibling, 1 reply; 5+ messages in thread
From: Tomas Hala via ntg-context @ 2021-08-27 20:56 UTC (permalink / raw)
To: Pablo Rodriguez via ntg-context; +Cc: Tomas Hala, Pablo Rodriguez
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: getting path and filename from url
2021-08-27 18:53 getting path and filename from url Pablo Rodriguez via ntg-context
2021-08-27 20:56 ` Tomas Hala via ntg-context
@ 2021-08-27 23:17 ` Hans Hagen via ntg-context
2021-08-28 9:19 ` Pablo Rodriguez via ntg-context
1 sibling, 1 reply; 5+ messages in thread
From: Hans Hagen via ntg-context @ 2021-08-27 23:17 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Hans Hagen, Pablo Rodriguez
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: getting path and filename from url
2021-08-27 20:56 ` Tomas Hala via ntg-context
@ 2021-08-28 9:18 ` Pablo Rodriguez via ntg-context
0 siblings, 0 replies; 5+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2021-08-28 9:18 UTC (permalink / raw)
To: Tomas Hala via ntg-context; +Cc: Pablo Rodriguez
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: getting path and filename from url
2021-08-27 23:17 ` Hans Hagen via ntg-context
@ 2021-08-28 9:19 ` Pablo Rodriguez via ntg-context
0 siblings, 0 replies; 5+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2021-08-28 9:19 UTC (permalink / raw)
To: Hans Hagen via ntg-context; +Cc: Pablo Rodriguez
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-08-28 9:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-27 18:53 getting path and filename from url Pablo Rodriguez via ntg-context
2021-08-27 20:56 ` Tomas Hala via ntg-context
2021-08-28 9:18 ` Pablo Rodriguez via ntg-context
2021-08-27 23:17 ` Hans Hagen via ntg-context
2021-08-28 9:19 ` Pablo Rodriguez via ntg-context
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).