2

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 world.this is. some test}{match}{NO~match}
  \ExplSyntaxOff
\end{document}
bp2017
  • 3,756
  • 1
  • 13
  • 33
  • 7
    Page 233 of interface3.tex (at the end of the l3regex part) says: "The following features are likely to be implemented at some point in the future: • General look-ahead/behind assertions." So I suppose it's not possible yet. You can open an issue/feature request in the LaTeX3 repo for this to be implemented. – Phelype Oleinik Nov 17 '19 at 20:09
  • 3
    you get a warning from your code. – Ulrike Fischer Nov 17 '19 at 20:09
  • 5
    @bp2017 I'd not call it a disappointment, rather too much work for too few people. l3regex alone is more than 3000 lines of code and was written mostly by Bruno, so I believe that what is not yet implemented is due to the amount of effort vs. the number of use cases. Should you have an use case and present it, I think that you stand better chances of having this implemented... – Phelype Oleinik Nov 17 '19 at 21:04
  • 5
    Look ahead/behind are not strictly regular, and at an implementation level, Bruno decided that the speed impact would be non-trivial – Joseph Wright Nov 17 '19 at 21:11
  • 1
    @bp2017 you don't even need to look in the log it is a warning not a info message, it is printed on the terminal as well as the log file. – David Carlisle Nov 18 '19 at 01:05
  • reading tracing in the log takes practice but running in scrollmode so you don't stop at errors and not looking in the log to see if there is an error before asking a question is I say always wrong no matter what the tex experience. This is a warning rather than an error, but if you get an error you shouldn't even look at the pdf output (as it is usually nonsense after an error). Note on answer to you other comment I didn't suggest that people should turn on tracing, simply check for top level user warnings and errors. – David Carlisle Nov 18 '19 at 19:35
  • 1
    @bp2017 Oh :-) That was just a loose reference, as it changes from version to version. Mine is really 233 (never trust page or code line numbers :-). That's exactly why I copied the relevant item. A more concrete reference would've been "Part XXVII The l3regex package", section 8 "Bugs, misfeatures, future work, and other possibilities." – Phelype Oleinik Nov 18 '19 at 20:04

1 Answers1

2

The LaTeX3 regex engine covers a documented set of features. In particular, look-behind is not currently implemented. The l3regex implementation uses a finite state automata, and it is possible to implement look around: see https://cs.stackexchange.com/questions/2557/how-to-simulate-backreferences-lookaheads-and-lookbehinds-in-finite-state-auto. However, the work is tricky and has not to-date been tackled.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036