How to stop Haskell Parsec parser at EOF
<p>So, I'm writing a small parser that will extract all <code>&lt;td&gt;</code> tag content with specific class, like this one <code>&lt;td class="liste"&gt;some content&lt;/td&gt; --&gt; Right "some content"</code></p>

<p>I will be parsing large <code>html</code> file but I don't really care about all the noise, so idea was to consume all characters until I reach <code>&lt;td class="liste"&gt;</code> than I'd consume all characters (content) until <code>&lt;/td&gt;</code> and return content string.</p>

<p>This works fine if last element in a file is my <code>td.liste</code> tag, but if I have some text after it or <code>eof</code> than my parser consumes it and throws <code>unexpected end of input</code> if you execute <code>parseMyTest test3</code>.</p>

<p>-- EDIT<br>
See end of <code>test3</code> to understand what is the edge case.</p>

<p>Here is my code so far :</p>

<pre><code>import Text.Parsec
import Text.Parsec.String

import Data.ByteString.Lazy (ByteString)
import Data.ByteString.Char8 (pack)

colOP :: Parser String
colOP = string "&lt;td class=\"liste\"&gt;"

colCL :: Parser String
colCL = string "&lt;/td&gt;"

col :: Parser String
col = do
  manyTill anyChar (try colOP)
  content &lt;- manyTill anyChar $ try colCL
  return content

cols :: Parser [String]
cols = many col

test1 :: String
test1 = "&lt;td class=\"liste\"&gt;Hello world!&lt;/td&gt;"

test2 :: String
test2 = read $ show $ pack test1

test3 :: String
test3 = "\n\r&lt;html&gt;asdfasd\n\r&lt;td class=\"liste\"&gt;Hello world 1!&lt;/td&gt;\n&lt;td class=\"liste\"&gt;Hello world 2!&lt;/td&gt;\n\rasldjfasldjf&lt;td class=\"liste\"&gt;Hello world 3!&lt;/td&gt;&lt;td class=\"liste\"&gt;Hello world 4!&lt;/td&gt;adsafasd"

parseMyTest :: String -&gt; Either ParseError [String]
parseMyTest test = parse cols "test" test

btos :: ByteString -&gt; String
btos = read . show
</code></pre>