一,部分属性

RegExp exp = new RegExp(r"(\w+)");

  • 返回正则表达式的哈希码

    print(exp.hashCode);
  • 正则表达式是否区分大小写

    print(exp.isCaseSensitive);
  • 正则表达式是否匹配多行

    print(exp.isMultiLine);
  • 返回源正则表达式字符串

    print(exp.pattern);
  • 返回对象运行时的类型

    print(exp.runtimeType);

二,常用方法

RegExp exp = new RegExp(r"(\w+)");

  • 返回正则表达式匹配项的可迭代对象

    print(exp.allMatches("abc def ghi"));
  • 搜索并返回第一个匹配项,没有则返回null

    print(exp.firstMatch(""));
  • 正则表达式是否找到匹配项

    print(exp.hasMatch("as"));
  • 从第几个字符开始匹配正则表达式

    print(exp.matchAsPrefix("ab cd", ));
  • 返回正则表达式的第一个匹配字符串

    print(exp.stringMatch("abc de"));
  • 返回正则表达式的字符串表示

    print(exp.toString());

三,实用案例

  • 验证邮政编码的正则,返回是否匹配的布尔值

    RegExp postalcode = new RegExp(r'(\d{6})');
    print(postalcode.hasMatch(""));
  • 验证手机号码的正则,以Iterable< Match >返回所有匹配项

    RegExp mobile = new RegExp(r"(0|86|17951)?(13[0-9]|15[0-35-9]|17[0678]|18[0-9]|14[57])[0-9]{8}");
    Iterable<Match> mobiles = mobile.allMatches("13812345678 12345678901 17012345678");
    for (Match m in mobiles) {
    String match = m.group();
     print(match);
    }
  • 验证网址URL的正则,如果匹配成功以Match返回匹配项,否则返回null

    RegExp url = new RegExp(r"^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+");
    print(url.firstMatch("http://www.google.com"));
  • 验证身份证号码的正则,返回第一个匹配的字符串

    RegExp identity = new RegExp(r"\d{17}[\d|x]|\d{15}");
    print(identity.stringMatch("My id number is 35082419931023527x"));

最新文章

  1. 密码备忘录(Android) 开发笔记
  2. oracle入门必备
  3. [译]git commit --amend
  4. SQL Server 索引分类
  5. php 预定义接口
  6. LINUX输入输出与文件
  7. Linux平台的boost安装全解
  8. C++函数后面加const修饰
  9. js控制文本框仅仅能输入中文、英文、数字与指定特殊符号
  10. Java Spring Boot VS .NetCore (一)来一个简单的 Hello World
  11. Zookeeper的Watcher 机制的实现原理
  12. tab下图片要求
  13. [NOIP2018]保卫王国
  14. Spring boot 整合hive-jdbc导致无法启动的问题
  15. 文档/视图(01):第一个Demo
  16. 蜗牛慢慢爬 LeetCode 25. Reverse Nodes in k-Group [Difficulty: Hard]
  17. Putty Technical Note
  18. postMan测试Controller接口
  19. webpack打包踩坑之TypeError: Cannot read property &#39;bindings&#39; of null
  20. python开发_re和counter

热门文章

  1. 浅析弹性公网IP付费模式和短时升配功能介绍
  2. 【HDOJ6604】Blow up the city(支配树)
  3. 【HDOJ6586】String(枚举)
  4. window系统命令cmd有哪些?
  5. TCP/IP协议 和 如何实现 互联网上点对点的通信
  6. [CSP-S模拟测试]:Tourist Attractions(简单图论+bitset)
  7. LintCode之奇偶分割数组
  8. 基于Java Agent的premain方式实现方法耗时监控(转),为了找到结论执行:premain在jvm启动的时候执行,所有方法前,会执行MyAgent的premain方法
  9. b/s 起点
  10. Debian 防火墙 打开 关闭