【发布时间】:2023-04-01 12:55:02
【问题描述】:
几个小时以来,我一直在尝试为这个标准问题找到正确的函数,例如在 Tcl shell 中:
str@suse131-intel:~> tclshi
% regexp -inline {[0-9]+} "I am trying this for the 1001. time!!"
1001
%
我已经尝试了很多,我可以找到比赛的开始和结束,但这不可能!我只得到一个最小的匹配,而不是一个急切的匹配。我应该手动挑选比赛吗? Ocaml 交互:
# let s1 = "this is the 1001. time I am trying this.";;
val s1 : string = "this is the 1001. time I am trying this."
# search_forward (regexp "[0-9]+") s1 0;;
- : int = 12
# group_beginning 0;;
- : int = 12
# group_end 0;;
- : int = 16
子问题:所有这些函数都引用了最后一个匹配项(“返回与最后一次调用匹配的 s 的子字符串,如文档所述”),如matched_string 看起来不是很FP,但正是对面的。我这个可重入和任务切换保存代码吗?
编辑:在昨天的会议中,我只收到了一个号码。现在我想将奇怪的行为复制到这个问题中,但它工作正常。问题可能是混合了不同的 let 定义。
完整示例:
# #require "str";;
/usr/lib64/ocaml/str.cma: loaded
# open Str;;
# let s1 = "this is the 1001. time I am trying this.";;
val s1 : string = "this is the 1001. time I am trying this."
# search_forward (regexp "[0-9]+") s1 0;;
- : int = 12
# matched_string s1;;
- : string = "1001"
【问题讨论】:
-
您可能想尝试新的ocaml-re 库。它更新了,可能 API 更好。
-
我知道,有 extlib、电池、Jane Street 的东西和......你说出来,但在深入研究这些之前,我想确定我已经理解了内置的 ocaml 的可能性模块。
-
@AshishAgarwal str 兼容 api 是同样丑陋的非线程安全的。我认为它的任何其他前端也不完整。