搜索插件、代码仓与 APP 分类

插件详情v1.0.0

verbal_expressions

一个帮助构建复杂正则表达式的包。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
71
喜欢数
20
Pub 分数
160

安装插件

flutter pub add verbal_expressions

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

VerbalExpressions 是一个 Dart 包,旨在通过流畅且可读的 API 简化复杂正则表达式的创建。它允许开发者通过直观的方法链逐步构建正则表达式模式,降低出错概率并提高代码可维护性。适用于解析结构化文本或验证输入格式,该包在保留完整功能的同时,抽象了原始正则表达式语法的复杂性。该包支持所有主要平台,使其适用于跨平台应用。

适合场景

  • 文本模式验证
  • 输入净化
  • 从字符串中提取数据
  • 解析结构化日志
  • 构建可重用的正则表达式生成器

主要特点

  • 流畅的、可链式调用的 API
  • 可读且可维护的正则表达式构造
  • 支持所有标准正则表达式操作
  • 跨平台兼容性
  • 轻松集成到Flutter应用

适合对象

  • 开发表单验证器的开发者
  • 注重代码可读性的团队
  • 需要动态正则表达式生成的项目
  • 处理用户输入或日志数据的应用程序

使用建议

  • 与原始正则表达式相比,可能会增加轻微开销
  • 不太适合极其简单的模式
  • 需要了解基本的正则表达式概念

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Pub Package Build Status Coverage Status Github Issues

verbal_expressions

A library for Dart developers that helps to construct difficult regular expressions.

Dart package info is here: https://pub.dartlang.org/packages/verbal_expressions

Quick start

  var regex = VerbalExpression()
   ..startOfLine()
   ..then("http").maybe("s")
   ..then("://")
   ..maybe("www.").anythingBut(" ")
   ..endOfLine();

  // Create an example URL
  String url = "https://www.google.com";

  // Use VerbalExpression's hasMatch() method to test if the entire string matches the regex
  regex.hasMatch(url); //True

  regex.toString();   // Outputs the regex used: ^http(s)?\\:\\/\\/(www\\.)?([^\\ ]*)\$

  var regex = VerbalExpression()..startOfLine()..then("abc")..or("def");

  var testString = "defzzz";
  //Use VerbalExpression's hasMatch() method to test if parts if the string match the regex
  regex.hasMatch(testString);   // true

Feel free to use any predefined char groups:

  var regex = VerbalExpression()
	  ..wordChar()..nonWordChar()
	  ..space()..nonSpace()
	  ..digit()..nonDigit();

Define captures:

  var expression = VerbalExpression()
   ..find("a")
   ..beginCapture()..find("b")..anything()..endCapture()
   ..then("cd");
   
  RegExp regex = expression.toRegExp();

  var match = regex.firstMatch(text);
  print(match.group(0)); // returns "abcd"
  print(match.group(1)); // returns "b"

Examples

More examples are in example file

Features and bugs

Please find feature requests and bugs at the issue tracker.

Other implementations

You can view all implementations on VerbalExpressions.github.io

[ Javascript - PHP - Python - C# - Objective-C - Ruby - Groovy - Haskell - C++ - ... (moarr) ]

所属分类

源码仓库

使用此插件的项目

暂无相关数据。