4

Can anyone explain these regular expressions using expl3 and how those works?

\regex_replace_all:nnN { a\-(ai) } { \1 } \l_mytrans_tl
\regex_replace_all:nnN { a\-(au) } { \1 } \l_mytrans_tl
\regex_replace_all:nnN { a\-([āiueoīū]{1}) } { \1 } \l_mytrans_tl
\regex_replace_all:nnN { a\-(rr) } { \1 } \l_mytrans_tl
\regex_replace_all:nnN { a\-(r) } { \1 } \l_mytrans_tl
\regex_replace_all:nnN { \-([āiueoīū]{1}) } { \1 } \l_mytrans_tl

Especially the last one. I could not figure out this.

0

1 Answer 1

9

The last line should replace by ā, -i by i, -u by u and so on.

To break it up:

  • \- represents the character -.
  • Next, everything wrapped in parenthesis (...) is the part of the string that should be use for the replacement.
  • Then follows a group wrapped in square brackets [...], which essentially means "one of these".
  • Following a repetition marker {1} meaning the character or group before "exactly once".
  • As for the replacement, \1 selects the first selection of the string, that is, the first part wrapped in parenthesis (...), which is [āiueoīū]{1} in this case.

So, it means replace a - followed by one of āiueoīū, but only exactly one character of these, by this very character. Essentially, it removes the -.

See the documentation of the l3regex package which is currently included in the doc of the LaTeX3 interfaces (chapter 8).

4
  • @Jasper Habicht Thanks for your nice explanation. Can you give me an example explaining this line? What is the function of first a before \ in this line? \regex_replace_all:nnN { a\-([āiueoīū]{1}) } { \1 } \l_mytrans_tl
    – mmr
    Nov 1, 2021 at 18:29
  • 1
    a is just the letter a. For example, the first line replaces a-ai by ai. Nov 1, 2021 at 18:29
  • 1
    Got it. thanks a bunch.
    – mmr
    Nov 1, 2021 at 18:30
  • 1
    \regex_replace_all:nnN { a\-([āiueoīū]{1}) } { \1 } \l_mytrans_tl does the very same like the last line, except that it removes a- and not just -. Nov 1, 2021 at 18:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .