Page 1 of 1

Issue with preg_match_all -

Posted: Tue Aug 10, 2010 5:14 am
by slaparound
Hi,

I have a problem with regex that I can't seem to find out what is. I am trying to extract everything between a \begin{spm} tag and a \end{spm} in a tex-document, using preg_match_all(). The regex that I have used (and verified at a regex-checker) is:
[text]\\begin{spm}(.*)\\end{spm}[/text]
Using php, the code would be:

Code: Select all

$texfil = file_get_contents("test.tex"); 		
preg_match_all('/\\begin{spm}(.*)\\end{spm}/',$texfil,$matches);
echo "<pre>".print_r($matches,true);
The content of the file is:
[text]\begin{spm}
\section{A question}
\subsection{Thats why:}
\paragraph{En av de fire musketeer er slik.}
\paragraph{En venn av Moses}
\end{spm}[/text]

Does anyone have any suggestions to why the $matches array returns nothing when running this regex?

Re: Issue with preg_match_all -

Posted: Tue Aug 10, 2010 8:02 am
by MindOverBody
I played yesterday with regex, and came up with parser class.
You might find it usefull. ;)

viewtopic.php?f=1&t=119749