Multiline Matching in Haskell Posix

后端 未结 3 1970
深忆病人
深忆病人 2021-01-06 07:09

I can\'t seem to find decent documentation on haskell\'s POSIX implementation. Specifically the module Text.Regex.Posix.

Can anyone point me in the rig

相关标签:
3条回答
  • 2021-01-06 07:50

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

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

    Well, since Text.Regex.Posix's defaultCompOpt = compExtended + compNewline, that works out equivalently as

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

    To pull out just 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 compExtended defaultExecOpt
                  "<textarea[^>]*id=\"wpTextbox1\"[^>]*>(.*)</textarea>"
    
    0 讨论(0)
  • 2021-01-06 07:59

    You may need to use the PCRE backend instead if you want to do anything more flexible, or with better performance, than Posix regexes.

    pcre-light and regex-pcre are both fine.

    0 讨论(0)
  • 2021-01-06 08:11

    I solved in this case by matching

    ((.*)|\n*)*
    

    Although this may not always work depending on your expression. The above solution is probably the best way to go if you're able to.

    0 讨论(0)
提交回复
热议问题