[NTG-pdftex] \ptexmatch (was: Patch EscapeAndOther)

Martin Schröder martin at oneiros.de
Sat Jul 2 21:39:48 CEST 2005


On 2005-06-25 03:52:01 +0200, Heiko Oberdiek wrote:
> \pdfmatch [icase] [subcount <number>}] {<pattern>}{<string>}
>   Implements pattern matching using the POSIX regex
>   (a standard library at least in my linux).
>   It returns the same values as \pdfstrcmp, but
>   with the following semantics:
>     -1: error case (invalid pattern, ...)
>      0: no match
>      1: match found
>   Options:
>   * icase: case insensitive matching
>   * subcount: it sets the table size for found subpatterns.
>     A number "-1" resets the table size to the start default.
> 
>   See the manual page regex.3 and regex.7.
> 
>   The implementation shows a possible interface to
>   pattern matching in TeX. Therefore only the basics
>   is implemented.
>   Flags:
>   * REG_EXTENDED is set in the implementation.
>   * REG_ICASE: can be set by user.
>   * other: not implemented.
> 
> \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 in the following
>   manner to avoid another primitive:
>     <position> "->" <match string>
>   "->" is used as separator in the tradition of \meaning.
>   There exists macros for parsing the output of \meaning
>   (e.g. in LaTeX: \strip at prefix).
>   The position "-1" with an empty string indicates that
>   this entry is not set.
>   Example:
>     \def\msg#{\immediate\write16 }
>     \msg{\pdfmatch{(l+)o (W(o))}{Hello World}}
>     \msg{\pdflastmatch0}
>     \msg{\pdflastmatch1}
>     \msg{\pdflastmatch2}
>     \msg{\pdflastmatch3}
>     \msg{\pdflastmatch4}
>   Result:
>     1
>     2->llo Wo
>     2->ll
>     6->Wo
>     7->o
>     -1->

How can one inquire the number of matches found, i.e. the size of
the array? This would be sub_match_count in utils.c .

Or does one have to parse increasing \ptexlastmatch'es till one
get's a -1?

Best
    Martin
-- 
                    http://www.tm.oneiros.de


More information about the ntg-pdftex mailing list