Home  >  Article  >  Web Front-end  >  javascript regular expression (1)_javascript skills

javascript regular expression (1)_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:27:09819browse
Direct variable character of regular expression:
字符 匹配
o NUL字符
t 制表符
n 换行符
v 垂直制表符
f 换页符
r 回车
xnn 由十六进制nn指定的拉丁符,比如:x0A等价于
uxxxx unicode字符
cX 控制字符^X

JS reference of regular expression: var sEnd=new RegExp("s$"); ——String matching ending with s


Regular expression:

Verified characters:
has special meaning in regular expressions, they are:
^ $ . * ! : | / () [] {} We will research it later
If you use these punctuation marks as literals in regular expressions, they must be preceded by "" (escape character).
Other characters (such as @ and quotation marks) have no special meaning, and only match themselves according to the direct value in the regular expression. Note:——“”

Question: "A[B]C[D]E[F]G" is divided into two arrays, namely ACEG and [B][D][F].

Question: Both are looking for the

[B][D][F] array. Which one is better?


Method 1: var test1 = test.match(/[(w)*]/g);

Method 2: var s = /[(w)*]/g;
var result;
var test1 = [];

while ((result = s.exec(test)) ! = null) { test1.push(result[0]); }
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn