We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
const reg = /abc/i
const reg = new RegExp('abc', 'i')
/abc/i.test('Abc')
'AbcdaBc'.match(/abc/ig)
'AbcdaBc'.replace(/abc/ig, '***')
'AbcdaBc'.split(/abc/i)
/^https?:\/\//
/^(?=.*[0-9])(?=.*[a-z])[0-9a-z]{6,12}$/i
someString.replace(/(某主席|某主任|某某某)/g, m => '*'.repeat(m.length))
/^[0-9]+(\.[0-9]{0,2})?$/
VS Code 有个插件 [change-case](https://marketplace.visualstudio.com/items?itemName=wmaurer.change-case) 可以实现字符的多种转换。我们拿其中一种举例,期望实现比如cardTitleExtra和card-title-extra的互相转换。
cardTitleExtra
card-title-extra
解法如下:
// cardTitleExtra --> card-title-extra someString.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`) // card-title-extra --> cardTitleExtra someString.replace(/-(.)/g, (m, p) => p.toUpperCase())
如何把 markdown 格式的字符串转换为对应的 html 字符串?
解法可以参考一些开源库的实现,比如[Marked](https://github.com/markedjs/marked/blob/master/lib/marked.js)。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
创建一个正则表达式
const reg = /abc/i
const reg = new RegExp('abc', 'i')
与正则有关的几个方法
/abc/i.test('Abc')
'AbcdaBc'.match(/abc/ig)
'AbcdaBc'.replace(/abc/ig, '***')
'AbcdaBc'.split(/abc/i)
工作中常用的几个正则
校验 URL 是否以 http:// 或者 https:// 开头
/^https?:\/\//
校验密码只包含数字和字母,且必须两者都包含,长度为 6 到 12 位
/^(?=.*[0-9])(?=.*[a-z])[0-9a-z]{6,12}$/i
把敏感词替换为 * 号
someString.replace(/(某主席|某主任|某某某)/g, m => '*'.repeat(m.length))
校验输入只能为数字,并且最多带两位小数
/^[0-9]+(\.[0-9]{0,2})?$/
其它正则的应用场景
驼峰、连字符相互转换
VS Code 有个插件 [change-case](https://marketplace.visualstudio.com/items?itemName=wmaurer.change-case) 可以实现字符的多种转换。我们拿其中一种举例,期望实现比如
cardTitleExtra
和card-title-extra
的互相转换。解法如下:
markdown 语法解析
如何把 markdown 格式的字符串转换为对应的 html 字符串?
解法可以参考一些开源库的实现,比如[Marked](https://github.com/markedjs/marked/blob/master/lib/marked.js)。
写在最后
The text was updated successfully, but these errors were encountered: