且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Erlang中的字符串正则表达式匹配

更新时间:2022-10-20 08:20:16

使用 re 模块,例如:

  ... 
字符串= AAPL,2010年5月7日15:58,21.34,21.36,21.34,21.35,525064\n,
RegExp = ^ AAPL,*,
例re:run(String,RegExp)
{match,Captured}-> ...;
nomatch-> ...
结尾,
...


How would I do regex matching in Erlang?

All I know is this: f("AAPL" ++ Inputstring) -> true.

The lines that I need to match "AAPL,07-May-2010 15:58,21.34,21.36,21.34,21.35,525064\n"

In Perl regex: ^AAPL,* (or something similar)

In Erlang?

Use the re module, e.g.:

...
String = "AAPL,07-May-2010 15:58,21.34,21.36,21.34,21.35,525064\n",
RegExp = "^AAPL,*",
case re:run(String, RegExp) of
  {match, Captured} -> ... ;
  nomatch -> ...
end,
...