\hypertarget{qore_regex_qore_regex_intro}{}\section{Qore Regular Expression Introduction}\label{qore_regex_qore_regex_intro}
Regular expression functionality in Qore is provided by \href{http://www.pcre.org}{\tt P\+C\+R\+E\+: Perl-\/\+Compatible Regular Expression library}.

Using this library, Qore implements regular expression pattern matching using very simple syntax with semantics similar to those of \href{http://www.perl.org}{\tt Perl 5}. One difference between Qore and Perl to keep in mind is that \hyperlink{qore_regex_qore_regex_backreferences}{backreferences} in Qore are referenced as {\ttfamily \$1}, {\ttfamily \$2}, {\ttfamily \$3}, etc which differs from Perl\textquotesingle{}s syntax (which uses numbered backslashes instead).

\begin{DoxyParagraph}{Examples\+:}

\begin{DoxyCode}
\textcolor{comment}{# call process() if the string starts with an alphanumeric character}
\textcolor{keywordflow}{if} (str =~ /^[[:alnum:]]/)
    process(str);
\end{DoxyCode}
 
\begin{DoxyCode}
\textcolor{comment}{# example of using regular expressions in a switch statement}
switch (str) \{
    case /^[^[:alnum:]]/: \textcolor{keywordflow}{return} \textcolor{keyword}{True};
    case /^[0-9]/: \textcolor{keywordflow}{return} \textcolor{keyword}{False};
    default: throw \textcolor{stringliteral}{"ERROR"}, \hyperlink{group__string__functions_ga7a74be141f814ef286046c367b21091c}{sprintf}(\textcolor{stringliteral}{"invalid string %y"}, str);
\}
\end{DoxyCode}
 
\begin{DoxyCode}
\textcolor{comment}{# regular expression substitution + ignore case & global options}
str =~ s/abc/xyz/gi;
\end{DoxyCode}
 
\begin{DoxyCode}
\textcolor{comment}{# prefix all non-alphanumeric characters with a backslash}
str =~ s/([^[:alnum:]])/\(\backslash\)\(\backslash\)$1/g;
\end{DoxyCode}
 
\begin{DoxyCode}
\textcolor{comment}{# regular expression substring extraction}
*list l = (str =~ x/(?:(\(\backslash\)w+):(\(\backslash\)w+):)(\(\backslash\)w+)/);
\end{DoxyCode}

\end{DoxyParagraph}
\hypertarget{qore_regex_qore_regex_operators}{}\section{Qore Regular Expression Operators}\label{qore_regex_qore_regex_operators}
The following is a list of operators based on regular expressions (or similar to regular expressions in the case of the transliteration operator).

{\bfseries Regular Expression Operators}  \tabulinesep=1mm
\begin{longtabu} spread 0pt [c]{*{2}{|X[-1]}|}
\hline
{\bfseries Operator} &{\bfseries Description}  \\\cline{1-2}
\hyperlink{operators_regex_match_operator}{Regular Expression Match Operator (=$\sim$)} &Returns \hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True} if the regular expression matches a string  \\\cline{1-2}
\hyperlink{operators_regex_no_match_operator}{Regular Expression No Match Operator (!$\sim$)} &Returns \hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True} if the regular expression does not match a string  \\\cline{1-2}
\hyperlink{operators_regex_subst_operator}{Regular Expression Substitution Operator} &Substitutes text in a string based on matching a regular expression  \\\cline{1-2}
\hyperlink{operators_regex_extract_operator}{Regular Expression Pattern Extraction Operator} &Returns a list of substrings in a string based on matching patterns defined by a regular expression  \\\cline{1-2}
\hyperlink{operators_transliteration_operator}{Transliteration Operator} &Not a regular expression operator; transliterates one or more characters to other characters in a string  \\\cline{1-2}
\end{longtabu}


See the table below for valid regular expression options.\hypertarget{qore_regex_qore_regex_options}{}\subsection{Qore Regular Expression Operator Options}\label{qore_regex_qore_regex_options}
{\bfseries Regular Expression Options}  \tabulinesep=1mm
\begin{longtabu} spread 0pt [c]{*{2}{|X[-1]}|}
\hline
{\bfseries Option} &{\bfseries Description}  \\\cline{1-2}
{\ttfamily i}  &Ignores case when matching  \\\cline{1-2}
{\ttfamily m}  &makes start-\/of-\/line ({\ttfamily $^\wedge$}) or end-\/of-\/line ({\ttfamily \$}) match after or before any newline in the subject string  \\\cline{1-2}
{\ttfamily s}  &makes a dot ({\ttfamily .}) match a newline character  \\\cline{1-2}
{\ttfamily x}  &ignores whitespace characters and enables comments prefixed by {\ttfamily \#}  \\\cline{1-2}
{\ttfamily g}  &makes global substitutions or global extractions (only applicable with the substitution and extraction operators)  \\\cline{1-2}
\end{longtabu}
\hypertarget{qore_regex_qore_regex_functions}{}\section{Qore Regular Expression Functions}\label{qore_regex_qore_regex_functions}
The following is a list of functions providing regular expression functionality where the pattern may be given at run-\/time\+:

{\bfseries Regular Expression Functions}  \tabulinesep=1mm
\begin{longtabu} spread 0pt [c]{*{2}{|X[-1]}|}
\hline
{\bfseries Function} &{\bfseries Description}  \\\cline{1-2}
\hyperlink{group__string__functions_ga7804f63df9b181e0bacb465eb912feb9}{regex()} &Returns \hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True} if the regular expression matches a string  \\\cline{1-2}
\hyperlink{group__string__functions_gad8963269da93fe1ebaa179dab8d315fa}{regex\+\_\+subst()} &Substitutes a pattern in a string based on regular expressions and returns the new string  \\\cline{1-2}
\hyperlink{group__string__functions_ga9f8c21f961daa29578dcfd596f5871ff}{regex\+\_\+extract()} &Returns a list of substrings in a string based on matching patterns defined by a regular expression  \\\cline{1-2}
\end{longtabu}
\hypertarget{qore_regex_qore_regex_backreferences}{}\subsection{Qore Regular Expression Backreferences}\label{qore_regex_qore_regex_backreferences}
\hyperlink{namespace_qore}{Qore} uses {\ttfamily \$}{\itshape num} for backreferences in regular expression substitution expressions. The first backreference is {\ttfamily \$1}, the second \$2, and so on.

\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
\textcolor{comment}{# prefix all non-alphanumeric characters with a backslash}
str =~ s/([^[:alnum:]])/\(\backslash\)\(\backslash\)$1/g;
\end{DoxyCode}
 
\begin{DoxyCode}
\textcolor{comment}{# remove parentheses from string at the beginning of the line}
str =~ s/^\(\backslash\)((.*)\(\backslash\))/$1/;
\end{DoxyCode}
 
\end{DoxyParagraph}
