【发布时间】:2017-07-13 18:35:04
【问题描述】:
我正在尝试 Reason,我正在尝试使用正则表达式,但没有任何匹配项。 AFAIK Reason 没有任何特定的正则表达式相关的东西,所以我只是离开 OCaml 文档。
我的字符串看起来像:
let name = "const {foo} = bar";
我使用的正则表达式是
let re = Str.regexp_string "\\bfoo\\b"
try {
Str.search_forward re name 0;
/* do something */
} {
| Not_found => acc
}
但我没有得到任何匹配。有人可以帮忙吗?
编辑:作为参考,OCaml 的正则表达式文档可以在https://caml.inria.fr/pub/docs/manual-ocaml/libref/Str.html 找到。我使用 http://pleac.sourceforge.net/pleac_ocaml/patternmatching.html 作为 OCaml 正则表达式的示例,但我无法让它工作。
【问题讨论】:
-
你能把 link 贴到你用来找出它支持的正则表达式语法的页面吗?谢谢!
-
单词边界后面的斜线怎么办?
-
不应该是
"\\bfoo\\b"结尾不带斜线吗? -
@bobblebubble 哎呀,当我对问题进行格式化时,最后的斜线是一个错字。不应该在那里。没有它仍然无法工作。