* problem with string matching
@ 2020-10-10 14:32 Pablo Rodriguez
0 siblings, 0 replies; only message in thread
From: Pablo Rodriguez @ 2020-10-10 14:32 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-10-10 14:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-10 14:32 problem with string matching Pablo Rodriguez
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).