mm_matchs
v1.1.8
Published
这是用来匹配复杂的字符串结构的函数,可以匹配前缀包含、后缀包含、以及时间、地点等
Downloads
81
Maintainers
Readme
mm_matchs
这是一个用于匹配复杂字符串结构的Node.js模块,提供了丰富的字符串匹配功能,可以匹配前缀包含、后缀包含、以及时间、地点等多种模式。
特点
- 支持多种匹配模式:前缀匹配、后缀匹配、正则匹配等
- 内置丰富的匹配规则:时间、日期、地点、网址等
- 使用简单,支持链式调用
- 可扩展性强,支持自定义匹配规则
安装
npm install mm_matchs基础用法
const Matchs = require('mm_matchs');
const ms = new Matchs();
// 使用String原型扩展方法
const str = "我叫文武, 手机号码是15817188866";
// 前缀匹配
console.log(str.matchs('手机号码*')); // 15817188866
// 后缀匹配
console.log(str.matchs('*武')); // 文武
// 区间匹配
console.log(str.matchs('如果*就*')); // 匹配两个通配符之间的内容内置匹配规则
时间日期类
// 匹配日期时间
str = "1991-04-01 12:15:36";
console.log(str.matchs('{日期时间}'));
// 匹配年月日
str = "1991年4月1日";
console.log(str.matchs('{年月日}'));
// 匹配时间
str = "现在的时间是19:35:59";
console.log(str.matchs('{时间}'));地理位置类
// 匹配省份
str = "广东省深圳市南山区";
console.log(str.matchs('{省份}'));
// 匹配城市
console.log(str.matchs('{城市}'));
// 匹配方位
console.log(str.matchs('{方位}'));网络通信类
// 匹配网址
console.log("http://www.example.com".matchs('{网址}'));
// 匹配邮箱
console.log("[email protected]".matchs('{邮箱}'));
// 匹配手机号码
console.log("13812345678".matchs('{手机号码}'));其他常用匹配
// 匹配身份证号
console.log("440123199001011234".matchs('{身份证号}'));
// 匹配车牌号
console.log("粤B12345".matchs('{车牌号}'));
// 匹配中英文
console.log("Hello世界".matchs('{中英文}'));API文档
主要方法
matchs(pattern): 字符串匹配方法,支持通配符和预定义规则tense(str, format): 匹配时态bearing(str, format): 匹配方位province(str, format): 匹配省份city(str, format): 匹配城市
预定义规则
模块内置了多种匹配规则,使用花括号{}包裹规则名称:
{日期时间}: 匹配日期时间格式{日期}: 匹配日期{时间}: 匹配时间{网址}: 匹配URL{邮箱}: 匹配电子邮箱{手机号码}: 匹配手机号{身份证号}: 匹配身份证号码{车牌号}: 匹配车牌号{中英文}: 匹配中英文混合
许可证
ISC License
作者
qww
