-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
略懂正则 #28
Labels
dtkb
don't know before
Comments
字符组
量词
|
惰性量词和贪婪量词
|
|
货币格式化
const format = num =>
num.toFixed(2).replace(/\B(?=(\d{3})+\b)/g, ',').replace(/^/, '$ ')
console.log(format(1888)) // $ 1,888.00 |
验证密码密码长度 6-12 位,由数字、小写字符和大写字母组成,但必须至少包括 2 种字符。
var regex = /^[0-9A-Za-z]{6,12}$/
var regex = /(?=.*[0-9])^[0-9A-Za-z]{6,12}$/
var regex = /(?=.*[0-9])(?=.*[a-z])^[0-9A-Za-z]{6,12}$/
/((?=.*[0-9])(?=.*[a-z])|(?=.*[0-9])(?=.*[A-Z])|(?=.*[a-z])(?=.*[A-Z]))^[0-9A-Za-z]{6,12}$/ 解释一下 还有, |
上题的另外一种解法“至少包含两种字符” 的意思就是说,不能全部都是数字,也不能全部都是小写字母,也不能全部都是大写 那么要求“不能全部都是数字”,对应的正则是:
最终答案是:
|
驼峰转中划线const dasherize = str =>
str.replace(/(?!^)([A-Z])/g, '-$1').replace(/[-_\s]+/g, '-').toLowerCase()
dasherize("MozTransform") // moz-transform |
操作符权重优先级从上至下,由高到低
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
一些例子
例子来自 老姚 正则迷你书v1.1
正则可视化来自 regulex
The text was updated successfully, but these errors were encountered: