2019年是正则表达式

问题描述 投票:0回答:1

Yesod经常使用Text

我想完全使用任何支持UTF8和Text的Regex库。

最推荐的两个库似乎是:

正则表达式尝试:

import          Text.Regex.TDFA
...
let (parta,partb,partc) = ((sometext :: Text) =~ ("de" :: String)) :: (String, String, String)

我似乎无法使用Text,即使regex-tdfa似乎具有用于Text的某种模块http://hackage.haskell.org/package/regex-tdfa-1.3.1.0/docs/Text-Regex-TDFA-Text.html

此处已安装堆栈的regex-tdfa版本是regex-tdfa-1.2.3.1,出于某种原因,它不会使用具有上述Text.Regex.TDFA.Text的较新版本。当我尝试在package.yaml中指定版本- regex-tdfa >=1.3.1时,使用“ yesod devel”构建时出现此错误:

In the dependencies for example-0.0.0(+dev +library-only):
    regex-tdfa-1.2.3.1 from stack configuration does not match >=1.3.1 
needed since backend is a build target.

[现有的SO问题:此问题的答案已过时,不建议使用regex-tdfa-text:Regular Expression on Yesod type Text

我如何使用支持Text的regex-tdfa版本?

PCRE尝试:

import          Text.Regex.PCRE
...
let stringResult = ( "hello there" :: Text ) =~ ( "e" :: Text ) :: AllTextMatches [] Text

除非我将所有的Text都替换为String,否则此操作将无效。错误是:

  • No instance for (RegexMaker Regex CompOption ExecOption Text)
        arising from a use of ‘=~’
    • In the expression:
          ("hello there" :: Text) =~ ("e" :: Text) :: AllTextMatches [] Text

本教程声称PCRE与UTF8一起使用:https://gabebw.com/blog/2015/10/11/regular-expressions-in-haskell

但是我不确定regex-pcre是否声称可以与Text一起使用。我应该将Text转换为String,然后使用regex-pcre吗?

摘要:

与Yesod一起使用正则表达式的最佳做法是什么?如何使用带有Text和UTF8的库?

haskell yesod haskell-stack
1个回答
0
投票

关于依赖性的错误消息之后,您应该看到显示以下文本:

Some different approaches to resolving this:

  * Set 'allow-newer: true' in /u/buhr/.stack/config.yaml to ignore all version
    constraints and build anyway.

  * Recommended action: try adding the following to your extra-deps 
    .../yesodtest/stack.yaml:

- regex-tdfa-1.3.1.0@sha256:c77808a0d68d275c75fb84dc9ced340536574...

extra-deps解决方案是首选的解决方案。在特定于项目的stack.yaml中,添加:

extra-deps:
- regex-tdfa-1.3.1.0

(实际上并不需要详细的SHA256。)这会引发另一个错误,因为regex-base太旧,因此您还需要按照建议的操作添加它:

extra-deps:
- regex-tdfa-1.3.1.0
- regex-base-0.94.0.0

这足以使用yesod/simple为我建立一个resolver: lts-14.17模板。

© www.soinside.com 2019 - 2024. All rights reserved.