首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Erlang正则表达式的例证

2012-12-25 
Erlang正则表达式的例子http://zotonic.com/documentation/908/just-enough-zotonic-source-part-3-regula

Erlang正则表达式的例子

http://zotonic.com/documentation/908/just-enough-zotonic-source-part-3-regular-expressions

?

27> re:run("E-mail: xyz@pdq.com", "[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-z]{2,3}").{match,[{8,11}]}

Note: DO NOT use this pattern in production. It needs more refinement and much more testing.

What other goodies does re offer?
split(Subject, RE) -> SplitList

and

split(Subject, RE, Options) -> SplitList

Examples:

28> re:split("this/is/my/path","/").[<<"this">>,<<"is">>,<<"my">>,<<"path">>]

If you wish to use a pattern multiple times and boost perfomance, you can compile it with re:compile/1.

Example:

29>  {_, P} = re:compile("[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-z]{2,3}").{ok,{re_pattern,0,0,                <<69,82,67,80,164,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,64,                  ...>>}}30> re:run("E-mail: xyz@pdq.com", P).{match,[{8,11}]}

How are regular expressions used in Zotonic source?

For one of many examples, look at ../zotonic/src/markdown/get_url/1.

get_url(String) ->    HTTP_regex = "^(H|h)(T|t)(T|t)(P|p)(S|s)*://",    case re:run(String, HTTP_regex) of        nomatch    -> not_url;        {match, _} -> get_url1(String, [])    end.

热点排行