1

New TEX user here. I have a homework assignment for a regular expression:

RE = /\bgrotto\b.\braven\b.|\braven\b.*\b grotto\b/

However, every time I put \b, it sees it as a function. How can I get around this? Thank you!

Bernard
  • 271,350
ano
  • 11

1 Answers1

4

I can think of two solutions:

  • replace all instances of \ in the string with \textbackslash

  • Use inline verbatim mode, as the string expresses computer code

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc} % needed to render "|" correctly in text mode
\newcommand\tb\textbackslash
\begin{document}

RE = /\tb bgrotto\tb b.\tb braven\tb b.|\tb braven\tb b.*\tb b grotto\tb b/

\verb+RE = /\bgrotto\b.\braven\b.|\braven\b.*\b grotto\b/+

\end{document}
Mico
  • 506,678