Escape character in LaTeX

I need to output the below text but since \ is a special character, I cannot:

[RegularExpression(@"\d+")]


Also sometimes I need use dollar sign $ as well but it seems to be a special char, too. What is the way to escape those in LaTeX? UPDATE: I used \verb as suggested but I am unable to run commands inside it. Also, in the output the font and the opacity of the text is different than the default one: \verb|[RegularExpression(\newline @"\d+")]|  • – caw Oct 10 '13 at 0:09 3 Answers The following ten characters have special meanings in (La)TeX: & % $ # _ { } ~ ^ \

Outside \verb, the first seven of them can be typeset by prepending a backslash; for the other three, use the macros \textasciitilde, \textasciicircum, and \textbackslash.

\documentclass{article}

\begin{document}


# Replace a \ with $\backslash$
# This is made more complicated because the dollars will be escaped
# by the subsequent replacement. Easiest to add \backslash
# now and then add the dollars
$paragraph =~ s/\\/\\backslash/g; # Must be done after escape of \ since this command adds latex escapes # Replace characters that can be escaped$paragraph =~ s/([\$\#&%_{}])/\\$1/g;

# Replace ^ characters with \^{} so that $^F works okay$paragraph =~ s/(\^)/\\$1\{\}/g; # Replace tilde (~) with \texttt{\~{}}$paragraph =~ s/~/\\texttt\{\\~\{\}\}/g;

# Now add the dollars around each \backslash
$paragraph =~ s/(\\backslash)/\$$1\$/g;
return $paragraph; }  For example it will convert this: & %$ # _ { } ~ ^ \ \today


into this:

\& \% \$\# \_ \{ \} \texttt{\~{}} \^{}$\backslash\backslash\$today