Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a regex in LaTeX

Tags:

regex

latex

In a LaTeX report I am making I have to write a regex. There is only one in the whole report, so I don't really want to use packages and so on.

This is the regex I am talking about:

^\"((\w|\s)+)\"$

I came up with this for LaTeX:

\grave{ }\backslash\"'((\backslash w\| \backslash s)+)\backslash \"' \backslash \$

This gives me like 10 errors, and I can't really see what is wrong. Okay, it looks pretty bad but all the commands should work.

Thanks in advance,

Harm

like image 802
Harm De Weirdt Avatar asked Mar 27 '10 09:03

Harm De Weirdt


2 Answers

Use \verb/^\"((\w|\s)+)\"$/

like image 151
Rob Hyndman Avatar answered Oct 13 '22 07:10

Rob Hyndman


Perhaps the problem is that some of those commands (\backslash, \grave) want to be in math mode, but \" doesn't. Have you tried using \verb to include the regexp verbatim? I'm not sure if it'll look like you want (it'll be typeset in a tt font), but you could do this with something like:

...

In my project I'm using a regexp \verb@^\"((\w|\s)+)\"@ to do a thing.

...

like image 24
Mike Dinsdale Avatar answered Oct 13 '22 08:10

Mike Dinsdale