use*_*111 2 regex ocaml reason
我正在尝试Reason并且我正在尝试使用正则表达式,但没有任何匹配.AFAIK Reason没有任何特定的正则表达式相关的东西,所以我只是关闭OCaml文档.
我的字符串看起来像:
let name = "const {foo} = bar";
Run Code Online (Sandbox Code Playgroud)
我正在使用的正则表达式是
let re = Str.regexp_string "\\bfoo\\b"
try {
Str.search_forward re name 0;
/* do something */
} {
| Not_found => acc
}
Run Code Online (Sandbox Code Playgroud)
但我没有得到任何比赛.有人可以帮忙吗?
编辑:作为参考,可以在https://caml.inria.fr/pub/docs/manual-ocaml/libref/Str.html找到OCaml的正则表达式文档.我使用http://pleac.sourceforge.net/pleac_ocaml/patternmatching.html作为OCaml正则表达式的一个例子我无法让它工作.
它看起来像你误读了文档." Str.regexp_string s
返回一个与之完全匹配的正则表达式s
." 换句话说,有了你re
,Str.string_match re "\\bfoo\\b" 0
就会回归真实; 而你的定义re
相当于Str.regexp "\\\\bfoo\\\\b"
.你想要的是什么Str.regexp "\\bfoo\\b"
.
归档时间: |
|
查看次数: |
637 次 |
最近记录: |