Regular expression – Multi-line match in Haskell POSIX

I can’t seem to find suitable documentation on Haskell’s POSIX implementation.
Especially the module Text. Regex.Posix.

Anyone Can you point me in the right direction to use multi-line matching on strings?

A strange fragment:

> extractToken body = body =~ "]*id=\"wpTextbox1\"[^ >]*>(.*)" :: String

I am trying to extract the source of a Wikipedia page, but this method obviously fails when multiple lines are involved.

You may need to import Text.Regex.Base.RegexLike to access makeRegexOpts and friends.

extractToken body = match regex body where
regex = makeRegexOpts (defaultCompOpt-compNewline) defaultExecOpt
"]*id=\"wpTextbox1\" [^>]*>(.*)"

Well, because Text.Regex.Posix defaultCompOpt = compExtended compNewline, its effect is the same as

extractToken body = match regex body where
regex = makeRegexOpts compExtended defaultExecOpt
"]*id=\"wpTextbox1\"[^>]*>(.*) "

To extract only the first group, please use one of the other instances of RegexLike. One possibility is

extractToken body = head groups where
(preMatch, inMatch, postMatch, groups) =
match regex body :: (String, S tring, String, [String])
regex = makeRegexOpts compExtended defaultExecOpt
"]*id=\"wpTextbox1\"[^>]*>(.*) "

I can’t seem to find suitable documentation on Haskell’s POSIX implementation.
Especially the module Text. Regex.Posix.

< p>Can anyone point me in the right direction to use multi-line matching on strings?

A strange fragment:

> extractToken body = body =~ "]*id=\"wpTextbox1\"[^ >]*>(.*)" :: String

I am trying to extract the source of a Wikipedia page, but this method obviously fails when multiple lines are involved.

You may need to import Text.Regex.Base.RegexLike to access makeRegexOpts and friends.

extractToken body = match regex body where
regex = makeRegexOpts (defaultCompOpt-compNewline) defaultExecOpt
"]*id=\"wpTextbox1\"[^>]*>(.*)"

Well, because Text.Regex.Posix defaultCompOpt = compExtended compNewline, its effect is the same as

extractToken body = match regex body where 
regex = makeRegexOpts compExtended defaultExecOpt
"]*id=\"wpTextbox1\"[^>]*>(.*)"

To extract only the first group, use one of the other instances of RegexLike. One possibility is

extractToken body = head groups where
(preMatch, inMatch, postMatch, groups) =
match regex body :: (String, String, String, [String])
regex = makeRegexOpts compExt ended defaultExecOpt
"]*id=\"wpTextbox1\"[^>]*>(.*)"

Leave a Comment

Your email address will not be published.