Questions tagged [l3regex]

Regular expressions in LaTeX using the l3regex package. Since June 2017, the l3regex package is included in the LaTeX3 kernel code which is loaded by the expl3 package in LaTeX or expl3-generic in other formats.

l3regex is the name of a module in the expl3 kernel (for the future LaTeX3, but already usable) designed for playing with regular expressions. It features a syntax similar to the POSIX standard, with adaptations for LaTeX.

Until June 2017 it used to be necessary to explicitly load it with \usepackage{l3regex}. The June 2017 release of expl3 included the module in the kernel.

106 questions
10
votes
1 answer

Regex for a string with a command inside it

I have managed to create a command that takes an argument and does substitutions on it with l3regex. However, if the argument contains itself a command, the command name is printed in the output as if it was a…
lotomat
  • 527
6
votes
0 answers

\regexpatchcmd failing with LaTeX2e 2020-10-01 patch level 4: Use \cs_replacement_spec:N not \token_get_replace

I am trying to compile this MWE: \documentclass{article} \newcommand{\hello}{Hi world!} \usepackage{regexpatch} \regexpatchcmd{\hello}{Hi}{Hello}{}{} \begin{document} \hello \end{document} This worked on one MiKTeX system using LaTeX2e patch level…
bers
  • 5,404
6
votes
1 answer

Expandable math

I am trying to create a script which expands some easy to read and write commands into more full-blown math formulas which uses variables so that it first prints its names and then on a new line, it would print its values. For instance: So, instead…
Runar
  • 6,082
5
votes
0 answers

Understanding assertion matching in l3regex

This question is a bit specific and beyond the official interface of the l3regex library, but I'm trying to understand how exactly the library works here. Given the following example…
siracusa
  • 13,411
5
votes
1 answer

pkgloader is not finding l3regex

I would like to try a package which seems interesting, but it some dependencies are not satisfied. Here is my minimal example: \documentclass{article} \usepackage{pkgloader} \LoadPackagesNow \begin{document} pckloader…
R. N
  • 1,076
4
votes
1 answer

How can I match a control sequence using \regex_match?

How can I match a control sequence using \regex_match? This code \newcommand{\iw}[1]{\immediate\write16{#1}} \iw{1 should be true} \regex_match:nnTF {May} {May} {\iw{TRUE}} {\iw{FALSE}} \newcommand{\z}{May} \iw{2 should be true} \regex_match:nnTF…
MarkSenn
  • 125
3
votes
1 answer

With l3 regular expressions, how can I capture a command and replace it with its name?

I have an input of the form òf a clist containing commands, such as {\my_cmd1,\my_xx_cmd2,\cmd3}. I first iterate through this list and remove commmas, the backslash \ etc. I save the output in a |tl|. I wanted to then remove underscores "_", as it…
yannisl
  • 117,160
3
votes
2 answers

l3regex - Line by line splitting

I'd like to analyse the contents of an environment line by line, but the following minimalistic testing code fails by "printing" false. \documentclass{article} \ExplSyntaxOn \NewDocumentEnvironment{linebyline}{b}{ \seq_new:N \l_temp_seq …
projetmbc
  • 13,315
3
votes
2 answers

expl3: Match a regex pattern multiple times

I would like to match the pattern "start with >>" in a string and replace this with a command; and if multiple >> appear, it should match and replace multiple times. For example, given the string aaa>>bbb>>ccc, I would like to convert it into…
Jinwen
  • 8,518
3
votes
2 answers

How to get groups from a LaTex regex match?

\documentclass{article} \usepackage{hyperref} \usepackage{expl3} \hypersetup{ colorlinks=true, linkcolor=blue, filecolor=magenta, urlcolor=cyan, pdftitle={Overleaf Example}, …
3
votes
2 answers

l3regex replace multiplication with cdot

I am trying to use a combination of Latex and sage to create tasks for my pupils. Therefore I have to replace two different types of expressions 2*x shall become 2 x and x*3 shall become x\cdot…
3
votes
1 answer

Extracting the pagenumber of the first page of a section from the toc file

In a project I am working on, I use subfiles to compile a document, each containing one section. If I compile only the document containing some given section, I want the page number to be correct. One way to solve this would be to set the page…
malin
  • 3,727
  • 4
  • 23
  • 35
2
votes
1 answer

l3regex and csvsimple

I want to use a l3regex replacement together with a csv list. \documentclass[utf8,fleqn]{scrartcl} \usepackage{l3regex} \usepackage{csvsimple} \begin{filecontents*}{\jobname.csv} a*9-2*b-13.1*a \end{filecontents*} \begin{document} …
2
votes
1 answer

Why this (otherwise working) regular expression doesn't work in `expl3` (lookbehind syntax)?

Either expl3 doesn't support lookbehind or I'm doing something wrong. \documentclass[margin=5mm,varwidth]{standalone} \usepackage{expl3} \begin{document} \ExplSyntaxOn % must match dot that precedes "d" \regex_match:nnTF{(?<=d)\.}{hello…
bp2017
  • 3,756
  • 1
  • 13
  • 33
2
votes
1 answer

Deleting defined variables or assign within group

This is a followup to Egregs answer in the question Expandable math, The code is included here as an MWE. It would be a great help if I could somehow delete all previeously defined variables, or assign them only within a group. Another possibility…
Runar
  • 6,082
1
2