From: Pablo Rodriguez <oinos@gmx.es>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: problem with string matching
Date: Sat, 10 Oct 2020 16:32:50 +0200 [thread overview]
Message-ID: <da5b078c-0d08-81c2-ba49-b4b9c89be854@gmx.es> (raw)
Dear list,
I have this sample:
\starttext
\startluacode
a = "asdfasd123"
b = a:match("%d+")
context(b)
c = "123"
context(c)
if b==c then context("yes") else context("no") end
function document.numbers_only(str)
context(str:gsub("[%a%p]", ""))
end
function document.only_numbers(str)
context(str:match("%d+"))
end
function document.compare_strings(one, two)
if one == two then context("Yes") else context ("No") end
end
\stopluacode
\unexpanded\def\numbersonly#1%
{\ctxlua{document.numbers_only("#1")}}
\unexpanded\def\onlynumbers#1%
{\ctxlua{document.only_numbers("#1")}}
\unexpanded\def\comparestrings#1#2%
{\ctxlua{document.compare_strings("#1", "#2")}}
\def\rstring{abc123}
\numbersonly{abc123}
\onlynumbers{abc123}
\doifelse{\numbersonly{\rstring}}{abc123}{yes}{no}
\doifelse{abc123}{\onlynumbers{\rstring}}{yes}{no}
\comparestrings{\numbersonly{\rstring}}{123}
\comparestrings{123}{123}, \comparestrings{1}{123}
\stoptext
I need to extract the digits from a string, which actually comes from
the "--arguments" option in the command line.
I need to compare the string with real numbers. But for some reason
unknown to me, this is more complex than I thought.
Could anyone explain me what I am doing wrong?
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
___________________________________________________________________________________
reply other threads:[~2020-10-10 14:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=da5b078c-0d08-81c2-ba49-b4b9c89be854@gmx.es \
--to=oinos@gmx.es \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).