


首先,什么事正则表达式呢,其实引入概念很多时候并不能帮我们明白它到底是什么,所以我先简单描述下,正则表达式,其实就是一个记录字符串规则则的字符串,等我们看完这一部分,也就能明白它到底是什么了。
基本语法:正则表达式就是“/expression/”+表示搜索范围的符号。例如我们要找function这个关键词,就是/function/gi,其中g表示global,就是全局搜索,i表示ignor,就是忽略大小写。
在js中,我们通过RegExp类来实现。
这个类里面有很多很多的符号用来表示不同的索引方法,我先把这个表列一列:
元字符 | 说明 | 量词 | 说明 | 反义字符 | 说明 |
. | 匹配除了换行符号(\n)以外的任意字符 | * | 出现次数:[0,+∞) | \W | 字母,数字,下划线,汉字以外的字符 |
^ | 匹配字符串的开始 | + | 出现次数:[1,+∞) | \S | 空白字符以外的字符 |
$ | 匹配字符串的结束 | ? | 出现次数:[0,1] | \D | 数字以外的字符 |
\b | 匹配单词边界 | {n} | 出现次数:n | \B | 匹配非单词的边界 |
\d | 匹配数字 | {n,} | 出现次数:[n,+∞) | [^] | 在字符类中,^号后面的字符串以外的任意字符 |
\s | 匹配任意的空白符 | {n,m} | 出现次数:[n,m] | [-] | 匹配从-前字符到-后字符的字符串中的字符/数字 |
\w | 匹配字母,数字,下划线或汉字 |
In addition to the above symbols, there are three concepts: one is grouping, one is backreference, and the last is candidate.
Grouping: refers to enclosing strings with (), so that strings can be combined according to certain rules. At the same time, brackets can also be nested, such as using regular expressions to express the date format: var dateReg=/^(d{1,4})(-)(d{1,2}(-)(d{1 ,2})$), Of course, this method also has certain loopholes. Here we just express the format problem.
In addition to these, there are square brackets. For example, if you only want to match one of the letters x y z d w, then write [xyzdw]. If the match is continuous, such as numbers 0-4, then [0 -4], but this only represents one character.
If you want to write more than one, such as matching ac or bd, then use the "|" symbol and write (ac|bd).
For example, if we want to match a string containing only abc, we can write: abdReg=/^[abc] $/; The following is a complete example.
Reverse Directed reference: It is an application of regular expressions based on grouping. First of all, you need to know the group number: follow the order of the groups from left to right, marked by the left bracket, and start accumulating from 1. There are two ways to use it: $group number, or group number.
The second one is suitable for referencing groups in expressions. "" is an escape symbol, which has the same meaning as usual. It is used when matching reserved characters.
For example, we want to match a string that starts with abc, ends with abc, and has no limit in the middle: Reg=/^(abc)[a-z]*1$/; You can try this sentence in the example just now, I Tested and there were no errors.
Several commonly used matching regular expressions:
1. Matching date: reg=/^d{4}-(((0[13578]|(10|12))-(0[1-9] |[1-2]d|3[01]))|(02-(0[1-9])|[1-2]d)|((0[469]|11)-(0[1- 9]|[1-2]d|30)))$/g;
2. Matching time: reg=/^([0-1]d|[2][0-3](:([ 0-5]d)){2}$/g;
3. Matching email address: reg=/^([a-zA-Z]([0-9a-zA-Z]|(_))* @(([0-9a-zA-Z]|(_)) .) [a-zA-Z]{2,9})$/g;
4. Match Chinese characters: reg=/^[ u4e00-u9fa5] $/g;
Javascript operates cookies
I believe everyone knows what cookies are, so I just copied the definition without mercy.
The statements for operating cookies with js are as follows: document.cookie=name "="value ";expires=" date.toGMTString();
Next we will use cookies to record the user name and password for login

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Notepad++7.3.1
Easy-to-use and free code editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
