For learning purpose I'd point out what went wrong in your original attempts.
Attempt 1. escape characters manually
You need to escape all the characters, and for the pipe symbol either using T1 font encoding (recommended!) or escape them manually.
Refer to
Anyway, the following code works
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\newcolumntype{e}{>{\hsize=0.02\hsize}X}
\newcolumntype{s}{>{\hsize=0.18\hsize}X}
\newcolumntype{b}{>{\hsize=0.80\hsize}X}
\begin{table} [!htb]
%\small
\footnotesize
\caption{List of Regex Patterns to filter GitHub repositories.}
\begin{tabularx}{\columnwidth} {|e | s | b |}
\hline
\multicolumn{1}{|c|}{\textbf{ID}} &
\multicolumn{1}{c|}{\textbf{Secret Type}} &
\multicolumn{1}{c|}{\textbf{Regular Expression}}\
\hline \hline
65 & AWS API Secret & \textbackslash b([A-Za-z0-9+/]{40})[ \textbackslash r\textbackslash n'"\textbackslash x60] \ \hline
71 & Azure Client Secret & (?i)(%s).{0,20}([a-z0-9_\textbackslash.\textbackslash-~{}]{34}) \ \hline
278 & Generic Pattern & (?i)(?:pass|token|cred|secret|key)(?:.|[\textbackslash n\textbackslash r]){0,40}(\textbackslash b[\textbackslash x21-\textbackslash x7e]{16,64}\textbackslash b) \ \hline
605 & Slack Token & (xoxb$\vert$xoxp$\vert$xapp$\vert$xoxa$\vert$xoxr)-[0-9]10,13[a-zA-Z0-9]* \ \hline
640 & Stripe API Key & [rs]k_live_[a-zA-Z0-9]{20,30} \ \hline
\end{tabularx}
\end{table}
\begin{table} [!htb]
%\small
\footnotesize
\caption{List of Regex Patterns to filter GitHub repositories.}
\begin{tabularx}{\columnwidth} {|e | s | b |}
\hline
\multicolumn{1}{|c|}{\textbf{ID}} &
\multicolumn{1}{c|}{\textbf{Secret Type}} &
\multicolumn{1}{c|}{\textbf{Regular Expression}}\
\hline \hline
65 & AWS API Secret & \texttt{\textbackslash b([A-Za-z0-9+/]{40})[ \textbackslash r\textbackslash n'"\textbackslash x60]} \ \hline
71 & Azure Client Secret & \texttt{(?i)(%s).{0,20}([a-z0-9_\textbackslash.\textbackslash-~{}]{34})} \ \hline
278 & Generic Pattern & \texttt{(?i)(?:pass|token|cred|secret|key)(?:.|[\textbackslash n\textbackslash r]){0,40}\discretionary{}{}{}(\textbackslash b[\discretionary{}{}{}\textbackslash x21-\textbackslash x7e]{16,64}\textbackslash b)} \ \hline
605 & Slack Token & \texttt{(xoxb$\vert$xoxp$\vert$xapp$\vert$xoxa$\vert$xoxr)-[0-9]10,13[a-zA-Z0-9]*} \ \hline
640 & Stripe API Key & \texttt{[rs]k_live_[a-zA-Z0-9]{20,30}} \ \hline
\end{tabularx}
\end{table}
\end{document}
Attempt 2. use \verb
It's extremely difficult to escape all these characters correctly, however. As such, you can attempt to use \verb.
However,
\verb is explicitly documented to be unsupported in the tabularx documentation, so this is only a hack. Refer to how to use fancyvrb Verbatim in tabularx?
- In more recent version there's "partial support", but
! cannot be used as a delimiter.
\begin{tabularx}{2cm}{c}
\verb|a|
\verb|\\\a\b| % some spaces are managed
%\verb!a! % breaks!
\verb/a/
\end{tabularx}
Anyway, to fix the \verb problem I use my package cprotectinside, and you have to undo the hack by tabularx, so the end result is
\documentclass{article}
\usepackage{tabularx}
\usepackage{cprotectinside}
\begin{document}
\newcolumntype{e}{>{\hsize=0.02\hsize}X}
\newcolumntype{s}{>{\hsize=0.18\hsize}X}
\newcolumntype{b}{>{\hsize=0.80\hsize}X}
\let\normalverb\verb
\cprotectinside{@}{
\begin{table} [!htb]
%\small
\footnotesize
\caption{List of Regex Patterns to filter GitHub repositories.}
\begin{tabularx}{\columnwidth} {|e | s | b |}
\hline
\multicolumn{1}{|c|}{\textbf{ID}} &
\multicolumn{1}{c|}{\textbf{Secret Type}} &
\multicolumn{1}{c|}{\textbf{Regular Expression}}\
\hline \hline
65 & AWS API Secret & @\normalverb\b([A-Za-z0-9+/]{40})[ \r\n'"\x60]@ \ \hline
71 & Azure Client Secret& @\normalverb(?i)(%s).{0,20}([a-z0-9_\.\-~]{34})@ \ \hline
278& Generic Pattern & @\normalverb(?i)(?:pass|token|cred|secret|key)(?:.|[\n\r]){0,40}(\b\discretionary{}{}{}\normalverb[\x21-\x7e]{16,64}\b)@ \ \hline
605& Slack Token & @\normalverb(xoxb|xoxp|xapp|xoxa|xoxr)-[0-9]10,13[a-zA-Z0-9]*@ \ \hline
640& Stripe API Key & @\normalverb[rs]k_live_[a-zA-Z0-9]{20,30}@ \ \hline
\end{tabularx}
\end{table}
}
\end{document}
By the way, be careful of warnings. It's not recommended to redefine b...
Package array Warning: Redefining primitive column b on input line 8.
but it's not the concern here.
Alternative: lstinline
You still need to escape things, but it is easier than the standard escaping.
\documentclass{article}
\usepackage{tabularx}
\usepackage{listings}
\begin{document}
\newcolumntype{e}{>{\hsize=0.02\hsize}X}
\newcolumntype{s}{>{\hsize=0.18\hsize}X}
\newcolumntype{b}{>{\hsize=0.80\hsize}X}
\let\normalverb\verb
% set font of lstinline to use texttt font
\lstset{basicstyle=\ttfamily}
\begin{table} [!htb]
%\small
\footnotesize
\caption{List of Regex Patterns to filter GitHub repositories.}
\begin{tabularx}{\columnwidth} {|e | s | b |}
\hline
\multicolumn{1}{|c|}{\textbf{ID}} &
\multicolumn{1}{c|}{\textbf{Secret Type}} &
\multicolumn{1}{c|}{\textbf{Regular Expression}}\
\hline \hline
65 & AWS API Secret & \lstinline\\b([A-Za-z0-9+/]\{40\})[ \\r\\n'"\\x60] \ \hline
71 & Azure Client Secret& \lstinline(?i)(\%s).\{0,20\}([a-z0-9_\\.\\-~]\{34\}) \ \hline
278& Generic Pattern & \lstinline(?i)(?:pass|token|cred|secret|key)(?:.|[\n\r])\{0,40\}(\b\discretionary{}{}{}\lstinline[\\x21-\\x7e]\{16,64\}\\b) \ \hline
605& Slack Token & \lstinline(xoxb|xoxp|xapp|xoxa|xoxr)-[0-9]10,13[a-zA-Z0-9]* \ \hline
640& Stripe API Key & \lstinline[rs]k_live_[a-zA-Z0-9]\{20,30\} \ \hline
\end{tabularx}
\end{table}
\end{document}
\hsize=...\hsizecalculations appears to be invalid. The sum of the\hsizes should be 3 (the number of X-type columns), not 1. – Mico Jan 11 '23 at 02:03\verb! ... !can be used to typeset the regex. The rest would be formatting the table, so it has sufficient space to show your table content. Maybe by using different packages or by breaking the code at some point. – enthu Jan 11 '23 at 07:03