免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1367 | 回复: 1
打印 上一主题 下一主题

[函数] 匹配/替换函数 [复制链接]

论坛徽章:
27
水瓶座
日期:2014-08-22 21:06:34程序设计版块每日发帖之星
日期:2015-11-25 06:20:0015-16赛季CBA联赛之新疆
日期:2015-12-19 19:05:48IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:3315-16赛季CBA联赛之上海
日期:2016-04-15 19:51:31程序设计版块每日发帖之星
日期:2016-04-17 06:23:29程序设计版块每日发帖之星
日期:2016-04-23 06:20:00程序设计版块每日发帖之星
日期:2016-05-26 06:20:00每日论坛发贴之星
日期:2016-05-26 06:20:0015-16赛季CBA联赛之辽宁
日期:2017-02-16 23:59:47
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-06-29 11:50 |只看该作者 |倒序浏览
  1. Erlang/OTP 17 [erts-6.0] [64-bit] [smp:4:4] [async-threads:10]

  2. Eshell V6.0  (abort with ^G)
  3. 1> A = <<"Chinaunix is here">>.  
  4. <<"Chinaunix is here">>
  5. 2> l(re).   
  6. {module,re}
  7. 3> re:
  8. compile/1      compile/2      grun/3         inspect/2      module_info/0  
  9. module_info/1  replace/3      replace/4      run/2          run/3         
  10. split/2        split/3        ucompile/2     urun/3         
  11. 3> re:replace(A,<<here>>,<<there>>).
  12. ** exception error: bad argument
  13. 4> re:replace(A,<<"here">>,<<"there">>).
  14. [<<"Chinaunix is ">>,<<"there">>]
  15. 5> re:replace(A,<<"here">>,<<"there">>,[{return,binary}]).
  16. <<"Chinaunix is there">>
  17. 6>
复制代码
  1. 6> f().
  2. ok
  3. 7> A = ["aaa","bbb","ccc"].
  4. ["aaa","bbb","ccc"]
  5. 8> [X,Y|_] = A.
  6. ["aaa","bbb","ccc"]
  7. 9> X.
  8. "aaa"
  9. 10> Y.
  10. "bbb"
复制代码
  1. 11> f().
  2. ok
  3. 12> B={o,p,q,r,s,t}.
  4. {o,p,q,r,s,t}
  5. 13> {_,_,X,_} = B.
  6. ** exception error: no match of right hand side value {o,p,q,r,s,t}
  7. 14> {_,_,X,_,_,_} = B.
  8. {o,p,q,r,s,t}
  9. 15> X.
  10. q
  11. 16>
复制代码
  1. 16> f().
  2. ok
  3. 17>
  4. 17> A = <<"Chinaunix is here">>.                           
  5. <<"Chinaunix is here">>
  6. 18> binary:re
  7. referenced_byte_size/1  replace/3               replace/4               

  8. 18> binary:replace(A,<<"Chinaunix">>,<<"CU">>).
  9. <<"CU is here">>
  10. 19>
复制代码

论坛徽章:
1
天蝎座
日期:2013-12-06 18:23:58
2 [报告]
发表于 2014-07-08 14:43 |只看该作者
准确说是匹配/替换模式,  “=” 是非常重要的模式匹配符。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP