示例 - 正则表达式 - js [英] Example - regular expression - js

查看:60
本文介绍了示例 - 正则表达式 - js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个(天真)简单的密码检查程序,可以查找3到6个字符和至少一个数字:



Here is a (naively) simple password checker that looks for between 3 and 6 characters and at least one number:

let password = "abc123";
let checkPass = /(?=\w{3,6})(?=\D*\d)/;
checkPass.test(password); // Returns true





我为什么要使用'\D *'?

不能理解这个代码的这个字符的含义..

如果没有这个例子:bana12;



我尝试了什么:



带有此字符的代码,并搜索类似的示例答案。



why should i use the '\D*'?
can't understand the meaning of this character of this code..
with out this it would not work for example of: "bana12";

What I have tried:

code with out this character, and search for similar examples answers.

推荐答案

打开Expresso - 你知道,我建议你为之前的两个问题安装的应用程序。

现在,将正则表达式粘贴到正则表达式窗格中:

Open Expresso - you know, the app I suggested you install for both of your previous questions.
Now, paste the Regex into the "Regular Expression" pane:
(?=\w{3,6})(?=\D*\d)



在Regex Analyzer窗格中查看它是正确的。展开所有分支。

看看它如何解释 \ D * \d 是什么?



但是正则表达式没用。它明确地捕获任何东西,并且如果它确实没有用,因为它试图捕获两个后缀并将它们排除在外......


Look to it's right at the "Regex Analyzer" pane. Expand all branches.
See how it explains what \D*\d does?

But that Regex is useless. It explicitly capture nothing, and wouldn't work if it did since it's trying to capture two suffixes and exclude them both...


引用:

这是一个(天真)简单的密码检查器,可以查找3到6个字符和至少一个数字:

Here is a (naively) simple password checker that looks for between 3 and 6 characters and at least one number:



您滥用RegEx, RegEx用于检查字符串是否与'模式'匹配。

URL,电子邮件地址,十进制数,车牌等都遵循构造规则,模式。

使用 Debuggex 链接查看RegEx的漂亮图表并试验一些候选密码以查看匹配内容和不匹配内容。

这是一个链接RegEx文档:

perlre - perldoc.perl.org [ ^ ]

以下是帮助构建RegEx并调试它们的工具的链接:<无线电通信/>
.NET正则表达式测试程序 - 正则表达式风暴 [ ^ ]

Expresso正则表达式工具 [ ^ ]

< a href =http://regexr.com/> RegExr:Learn,Build,&测试RegEx [ ^ ]

在线正则表达式测试器和调试器:PHP,PCRE,Python,Golang和JavaScript [ ^ ]

这个显示RegEx是一个很好的图表,它非常有助于理解RegEx的作用: Debuggex:在线可视正则表达式测试器。 JavaScript,Python和PCRE。 [ ^ ]

此网站还在一个漂亮的图表中显示正则表达式,但无法测试与RegEx匹配的内容: Regexper [ ^ ]



Nota:RegEx是一个复杂的主题阅读文档是必须掌握的。


You are misusing RegEx, RegEx is used to check if a string match a 'pattern'.
Things like URL, Email address, decimal number, car plates are following rules of construct, the pattern.
Use the Debuggex link to see a nice graph of the RegEx and to experiment with some candidate password to see what match and what don't.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx: Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx: Regexper[^]

Nota: RegEx is a sophisticated subject reading documentation is mandatory to master it.


这篇关于示例 - 正则表达式 - js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆