正则表达式 不区分大小写_正则表达式 – 不区分大小写的正则表达式!

在 Haskell中使用带有选项(标志)的正则表达式的最佳方法是什么

我用

Text.Regex.PCRE

文档列出了一些有趣的选项,如compCaseless,compUTF8,…

但我不知道如何使用它们(=〜)

所有Text.Regex.*模块都大量使用类型类,它们具有可扩展性和“重载”类似的行为,但仅仅看到类型就不那么明显了.

现在,你可能已经从基本=〜匹配器开始了.

进群:960410445 即可获取书十套PDF!

5b3bc6e939a970f5464d4fbadd15db17.png
(=~) :: ( RegexMaker Regex CompOption ExecOption source , RegexContext Regex source1 target ) => source1 -> source -> target(=~~) :: ( RegexMaker Regex CompOption ExecOption source , RegexContext Regex source1 target, Monad m ) => source1 -> source -> m target

要使用=〜,必须存在RegexMaker的实例…用于LHS,RegexContext …用于RHS和结果.

class RegexOptions regex compOpt execOpt | ... | regex -> compOpt execOpt , compOpt -> regex execOpt , execOpt -> regex compOptclass RegexOptions regex compOpt execOpt => RegexMaker regex compOpt execOpt source | regex -> compOpt execOpt , compOpt -> regex execOpt , execOpt -> regex compOpt where makeRegex :: source -> regex makeRegexOpts :: compOpt -> execOpt -> source -> regex

所有这些类的有效实例(例如,regex = Regex,compOpt = CompOption,execOpt = ExecOption和source = String)意味着可以使用某些表单源的compOpt,execOpt选项编译正则表达式. (另外,给定一些正则表达式类型,只有一个compOpt,execOpt设置随之而来.但是很多不同的源类型都可以.)

class Extract sourceclass Extract source => RegexLike regex sourceclass RegexLike regex source => RegexContext regex source target where match :: regex -> source -> target matchM :: Monad m => regex -> source -> m target

所有这些类的有效实例(例如,regex = Regex,source = String,target = Bool)意味着可以匹配源和正则表达式以产生目标. (给定这些特定正则表达式和源的其他有效目标是Int,MatchResult String,MatchArray等)

把这些放在一起很明显=〜和= ~~只是简单的功能

source1 =~ source = match (makeRegex source) source1source1 =~~ source = matchM (makeRegex source) source1

而且= =和= ~~没有空间来传递makeRegexOpts的各种选项.

你可以做自己的

(=~+) :: ( RegexMaker regex compOpt execOpt source , RegexContext regex source1 target ) => source1 -> (source, compOpt, execOpt) -> targetsource1 =~+ (source, compOpt, execOpt) = match (makeRegexOpts compOpt execOpt source) source1(=~~+) :: ( RegexMaker regex compOpt execOpt source , RegexContext regex source1 target, Monad m ) => source1 -> (source, compOpt, execOpt) -> m targetsource1 =~~+ (source, compOpt, execOpt) = matchM (makeRegexOpts compOpt execOpt source) source1

可以像

"string" =~+ ("regex
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值