isRegexWith
isRegexWith
自定义正则表达
🍱 参数
RegExp
- 正则表达式string
- 字符串
🔥 返回值
boolean
- 判断结果
🚀 示例
import { isRegexWith } from 'atools-js';
const email =
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
isRegexWith(email, 'wangdaoo@yeah.net'); // true
isRegexWith(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, 'rgba(0,0,0,1)'); // false
💡 源码
source code
/atools/_regex/isRegexWith.ts
export const isRegexWith = (regex: RegExp, str: string): boolean => regex.test(str);