[Haskell-beginners] subRegex https? with anchor href tags

Shakthi Kannan shakthimaan at gmail.com
Sat Nov 12 11:30:39 CET 2011


Hi,

I am trying to replace every occurrence of http://URL or https://URL with:

  <a href="http://URL">  http://URL   </a>
  <a href="https://URL"> https://URL </a>

respectively in a text file. I tried with Text.Regex with an example:

Prelude> let s = "Google website is http://www.google.com in US"

Prelude> import Text.Regex

Prelude Text.Regex> let s3 = subRegex (mkRegex "https?:[^\\s\n\r]+") s
"<a href=\"\\1\"></a>"
Prelude Text.Regex> s3
"Google website is <a href=\"*** Exception: Ix{Int}.index: Index (1)
out of range ((0,0))
Prelude Text.Regex>

I then tried a simpler example:

Prelude Text.Regex> subRegex (mkRegex "e") "hello" "\\1"
"h*** Exception: Ix{Int}.index: Index (1) out of range ((0,0))

What could I be missing? I am using GHCi 6.12.3 on Fedora 14.
Appreciate any help in this regard.

Thanks,

SK

-- 
Shakthi Kannan
http://www.shakthimaan.com



More information about the Beginners mailing list