TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can one use \pdfmatch with regular expressions and where can one find a listing and description of all the available pdfTeX primitives and help on their use?


The latest issue of the pdfTeX documentation, now contains a small description with examples for the command.

share|improve this question
Unfortunately, many of the pdftex primitives are not properly documented. The pdftex source code seems to be the only definitive reference. – Lev Bishop Oct 20 '10 at 18:05
@Lev Bishop Thanks for your quick response. – Yiannis Lazarides Oct 20 '10 at 18:14
See patch 375: <sarovar.org/tracker/…;. – Martin Heller Oct 20 '10 at 19:10
@Yiannis: The documentation of Heiko Oberbiek's askinclude package has a section on how to use \pdfmatch. I have not yet studied this and the source code of pdftex, but I will when I get time. – Bruno Le Floch Jan 3 '11 at 21:30
groups.google.com/group/comp.text.tex/browse_thread/thread/… --- and --- groups.google.com/group/comp.text.tex/browse_thread/thread/… --- have extra pointers (Heiko Oberdiek in both cases). Sorry don't know how to make links in comments. – Bruno Le Floch Jan 4 '11 at 22:30
up vote 12 down vote accepted

See pdftex 1.30.0 announcement, in particular:

  - \pdfmatch [icase] [subcount <number>}] {<pattern>}{<string>}
    Implements pattern matching using the POSIX regex.
    It returns the same values as \pdfstrcmp, but with the following
      -1: error case (invalid pattern, ...)
       0: no match
       1: match found
    * icase: case insensitive matching
    * subcount: it sets the table size for found subpatterns.
      A number "-1" resets the table size to the start default.
  - \pdflastmatch <number>
    The result of \pdfmatch is stored in an array. The entry "0" contains
    the match, the following entries submatches. The positions of the
    matches are also available. They are encoded:
      <position> "->" <match string>
    The position "-1" with an empty string indicates that this entry is not
share|improve this answer

For regular expressions specifically, the l3regex package provides a cross-engine solution (needs eTeX and \strcmp).

For instance,

\regex_extract_all:nnN { \w+ } { Hello,~ world! } \l_foo_seq
\seq_show:N \l_foo_seq

shows Hello and world as the two items of the resulting sequence (list).

Here's a list of various questions of whose one answer uses l3regex

share|improve this answer
Admittedly, this is shameless self-promotion. But the l3regex package was partially written because there is no consistent engine support for regular expressions, so that is on topic here. – Bruno Le Floch Oct 22 '11 at 5:42
I saw it the other day, looks good, don't you want to give a rather longer example? – Yiannis Lazarides Oct 22 '11 at 7:04
@Yiannis: I'll try to think of better examples (those I put in the doc are rather pointless, since I don't know which applications would be typical :)). I gave a longer example (showing only the replacement feature) in answer to a question about removing dots depending on surrounding characters. – Bruno Le Floch Oct 22 '11 at 8:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.