From: Thangalin via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Thangalin <thangalin@gmail.com>
Subject: String substitution using regular expressions and backreferences
Date: Mon, 1 Aug 2022 12:58:53 -0700 [thread overview]
Message-ID: <CAANrE7rhsqOLkmxujXxjdQ9VDFTR1oLAE_k4re9XsbXK-5N1GA@mail.gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 1429 bytes --]
Hi list,
I'm looking to perform text replacements.
\definereplacement[SubstPostmeridian][
match={[Pp].[Mm].]},
replace={\cap{pm}}
]
The \replaceword command doesn't handle periods well. The translate module
doesn't seem flexible enough to cover edge cases. Consider the following
example document containing both sample inputs and sample outputs:
\starttext
{\bf Markdown Input}
Our grandmother clock rang 11 p.m. and we fled.
Our grandmother clock rang 11 p.m., so we fled.
Our grandmother clock rang 11 p.m. We fled.
\blank[big]
{\bf \ConTeXt{} Output}
Our grandmother clock rang 11 \cap{pm} and we fled.
Our grandmother clock rang 11 \cap{pm}, so we fled.
Our grandmother clock rang 11 \cap{pm}. We fled.
\stoptext
It would be most convenient to write:
% Strip periods from p.m.
\definereplacement[SubstPostmeridianLowercase][
match={[Pp].[Mm]. ([^:upper:])},
replace={\cap{pm} \1}
]
% Preserve terminal period for p.m. (e.e. cummings notwithstanding)
\definereplacement[SubstPostmeridianTerminal][
match={[Pp].[Mm]. ([:upper:])},
replace={\cap{pm}. \1}
]
% Apply a macron for lowercase 'c' (McAnulty, McGenius, etc.)
% Well, not quite a macron: https://tex.stackexchange.com/q/364024/2148
\definereplacement[SubstMac][
match={Mc([:upper:]\w)},
replace={M\macronbelow{c}\1}
]
The \1 may be problematic. Other sigils include $1 and #1, which may also
have issues.
Thank you!
[-- Attachment #1.2: Type: text/html, Size: 3056 bytes --]
[-- Attachment #2: Type: text/plain, Size: 496 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
next reply other threads:[~2022-08-01 19:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-01 19:58 Thangalin via ntg-context [this message]
2022-08-01 20:13 ` Wolfgang Schuster via ntg-context
2022-08-01 20:56 ` Thangalin via ntg-context
2022-08-25 19:44 ` Thangalin via ntg-context
2022-08-26 7:34 ` Hans Hagen via ntg-context
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=CAANrE7rhsqOLkmxujXxjdQ9VDFTR1oLAE_k4re9XsbXK-5N1GA@mail.gmail.com \
--to=ntg-context@ntg.nl \
--cc=thangalin@gmail.com \
/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).