


Detailed explanation of JavaScript regular expressions and cascading effects
Regular expression (regular expression) is a string matching pattern, used to check whether a string contains a string of a specified pattern. Let’s share JavaScript_regular expressions and cascading effects with everyone through this article. Friends who are interested should take a look together
1. Regular expression (regular expression)
is a string matching pattern, used to check whether a string contains a string of the specified pattern.
2. Creation of regular expressions
##
var reg = /white/; var reg = new RegExp("white","g");
3. The regular expression modifier
g performs global matching (finding all matches instead of stopping after the first match is found).i Case-insensitive
m Multi-line matching
4. Regular expression symbols
square brackets : Square brackets are used to find characters within a range: [abc] Find any characters between square brackets.[^abc] Find any characters not between square brackets.
[0-9] Find any number from 0 to 9.
[a-z] Find any character from lowercase a to lowercase z.
[A-Z] Find any character from uppercase A to uppercase Z.
[A-z] Find any character from uppercase A to lowercase z.
[adgk] Find any character within the given set.
[^adgk] Find any character outside the given set.
(red|blue|green) Find any specified option.
^ matches the beginning of a string
$ Matches the end of the string
\s Any whitespace character
\S Any non-whitespace character
\d Matches a numeric character, equivalent to [0-9]
\D Except for digits Any character, equivalent to [^0-9]
\w Matches a number, underscore, or alphabetic character, equivalent to [A-Za-z0-9_]
\W Any non-single character character, equivalent In [^a-zA-z0-9_]
. Any character except newline character
{n,} Matches the previous item n times, or multiple times
{n,m} Matches the previous item at least n times, but not more than m times
* Matches the previous item 0 times or multiple times, equivalent to {0,}
+ Match the previous item one or more times, equivalent to {1,}
? Matches the previous item 0 or 1 times, which means the previous item is optional, equivalent to {0,1}
5, properties of the RegExp object
global Whether the RegExp object has the flag g, which declares whether the given regular expression performs global matching. ignoreCase Whether the RegExp object has flag i, which declares whether the given regular expression performs case-insensitive matching. multiline Whether the RegExp object has the flag m, which declares whether the given regular expression performs multi-line matching.6. Methods of RegExp object
1. exec searches for characters that match the regular expression, returns the found value, and Determine its locationexec()The exec() method retrieves a specified value from a string. The return value is the found value. If no match is found, null is returned. Example 1:var patt1=new RegExp("e"); document.write(patt1.exec("The best things in life are free")); 由于该字符串中存在字母 "e",以上代码的输出将是: e2. test Retrieve the value specified in the string and return true or falsetest()The test() method retrieves the specified value in a string. The return value is true or false. Example:
var patt1=new RegExp("e"); document.write(patt1.test("The best things in life are free")); 由于该字符串中存在字母 "e",以上代码的输出将是: True
7. Analysis (email verification) var reg=/^\w+@\w+.[a -zA-Z]{2,3}(.[a-zA-Z]{2,3})?$/;
//Regular expression creation ^Start of string
$End of string
\wAny character letters and numbers, underscore
+ indicates that the previous character appears {1,}, one or more times.
@ Ordinary string
\w Any string ddd@123
. Any character except newline ddd@123.
[a-zA-Z] ddd@123.c ddd @123.n
{2,3} ddd@123.com ddd@123.net ddd@123.tv
(.[a-zA-Z]{2,3})? ddd@123. com.cn ddd@123.net
Password regularity:/^[a-zA-Z0-9]{4,10}$/
Birthday regularity:/^((19\d{2})|(200\d)) -(0?[1-9]|1[0-2])-(0?[1-9]|[1-2]\d|3[0-1])$/
Email regular: /^\w+@\w+(\.[a-zA-Z]{2,3}){1,2}$/
Postal code:/^\d{6}$/
Mobile phone number :/^1\d{10}$/
8. Methods of String object
match 找到一个或多个正则表达式的匹配
search 检索与正则表达式相匹配的值
replace 替换与正则表达式匹配的字符串
split 把字符串分割为字符串数组
9、select对象常用事件、方法和属性.
1、事件 onchange 当改变选项时调用的事件
2、方法 add() 向下拉列表中添加一个选项
示例:
var province=document.getElementById("selProvince").value; var city=document.getElementById("selCity"); city.options.length=0; switch(province){ case "河南省": city.add(new Option("郑州市","郑州市"),null); city.add(new Option("洛阳市","洛阳市"),null); break; …… }
3、属性:
options[] 返回包含下拉列表中的所有选项的一个数组
selectedIndex 设置或返回下拉列表中被选项目的索引号
length 返回下拉列表中的选项的数目
示例:
function get(){ var index=document.getElementById("fruit").selectedIndex; var len=document.getElementById("fruit").length; var show=document.getElementById("show"); show.innerHTML="被选选项的索引号为:"+index+"<br/>下拉列表选项数目为:"+len; }
4、Option对象常用属性:
text:设置或返回某个选项的纯文本值
value:设置或返回被送往服务器的值
10、数组常用的属性和方法。
属性 length 设置或返回数组中元素的数目
方法:
join( ) 把数组的所有元素放入一个字符串,通过一个的分隔符进行分隔
sort( ) 对数组的元素进行排序
****读取二维数组中的元素值:
var cityList = new Array(); cityList['河北省'] = ['邯郸市','石家庄市']; cityList['河南省'] = ['郑州市','洛阳市']; cityList['湖北省'] = ['武汉市','宜昌市']; for(var i in cityList){ document.getElementById("show").innerHTML+=i+"<br/>"; } for(var j in cityList){ for(var k in cityList[j]){ document.getElementById("show").innerHTML+=cityList[j][k]+" ”; } document.getElementById("show").innerHTML+="<br/>“; }
The above is the detailed content of Detailed explanation of JavaScript regular expressions and cascading effects. For more information, please follow other related articles on the PHP Chinese website!

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.


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 Linux new version
SublimeText3 Linux latest version

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version
God-level code editing software (SublimeText3)

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