javascipt 正则表达式英文版

1. Regular-expression literal characters Character Matches

Alphanumeric character Itself

\0 The NUL character (\u0000)

\t Tab (\u0009)

\n Newline (\u000A)

\v Vertical tab (\u000B)

\f Form feed (\u000C)

\r Carriage return (\u000D)

\xnn The Latin character specified by the hexadecimal number nn; for example, \x0A is the same as \n

\uxxxx The Unicode character specified by the hexadecimal number xxxx; for example, \u0009 is the same as \t

\cX The control character ^X; for example, \cJ is equivalent to the newline character \n

2. Regular expression character classes Character Matches

[...] Any one character between the brackets.

[^...] Any one character not between the brackets.

.  Any character except newline or another Unicode line terminator.

\w Any ASCII word character. Equivalent to [a-zA-Z0-9_].

\W Any character that is not an ASCII word character. Equivalent to [^a-zA-Z0-9_].

\s Any Unicode whitespace character.

\S Any character that is not Unicode whitespace. Note that \w and \S are not the same thing.

\d Any ASCII digit. Equivalent to [0-9].

\D Any character other than an ASCII digit. Equivalent to [^0-9].

[\b] A literal backspace (special case).

3. Regular expression repetition characters Character Meaning

{n,m} Match the previous item at least n times but no more than m times.

{n,} Match the previous item n or more times.

{n} Match exactly n occurrences of the previous item.

?  Match zero or one occurrences of the previous item. That is, the previous item is optional. Equivalent to {0,1}.

+ Match one or more occurrences of the previous item. Equivalent to {1,}.

* Match zero or more occurrences of the previous item. Equivalent to {0,}.

4。 Regular expression alternation, grouping, and reference characters Character Meaning

| Alternation. Match either the subexpression to the left or the subexpression to the right.

(...) Grouping. Group items into a single unit that can be used with *, +, ?, |, and so on. Also remember the characters that match this group for use with later references.

(?:...) Grouping only. Group items into a single unit, but do not remember the characters that match this group.

\n Match the same characters that were matched when group number n was first matched. Groups are subexpressions within (possibly nested) parentheses. Group numbers are assigned by counting left parentheses from left to right. Groups formed with (?: are not numbered.

5. Regular-expression anchor characters Character Meaning

^ Match the beginning of the string and, in multiline searches, the beginning of a line.

$ Match the end of the string and, in multiline searches, the end of a line.

\b Match a word boundary. That is, match the position between a \w character and a \W character or between a \w character and the beginning or end of a string. (Note, however, that [\b] matches backspace.)

\B Match a position that is not a word boundary.

(?=p) A positive lookahead assertion. Require that the following characters match the pattern p, but do not include those characters in the match.

(?!p) A negative lookahead assertion. Require that the following characters do not match the pattern p.

6. Regular-expression flags Character Meaning

i Perform case-insensitive matching.

g Perform a global matchthat is, find all matches rather than stopping after the first match.

m Multiline mode. ^ matches beginning of line or beginning of string, and $ matches end of line or end of string.

string.replace(regexp, replacement)

Characters Replacement

$1, $2, ..., $99  The text that matched the 1st through 99th parenthesized subexpression within regexp

$&  The substring that matched regexp

$'  The text to the left of the matched substring

$'  The text to the right of the matched substring

$$  A literal dollar sign

name.replace(/(\w+)\s*,\s*(\w+)/, "$2 $1");

text.replace(/"([^"]*)"/g, "''$1''");

text.replace(/\b\w+\b/g, function(word) {

return word.substring(0,1).toUpperCase( ) +

word.substring(1);

});

(0)

相关推荐

  • javascipt 正则表达式英文版

    1. Regular-expression literal characters Character Matches Alphanumeric character Itself \0 The NUL character (\u0000) \t Tab (\u0009) \n Newline (\u000A) \v Vertical tab (\u000B) \f Form feed (\u000C) \r Carriage return (\u000D) \xnn The Latin chara

  • javascipt匹配单行和多行注释的正则表达式

    在使用node.js时.如果我们使用.json文件存储一些配置时,希望加上一些注释. 但是由于读取时,是读取字符串 ,然后用JSON.parse 来 转换成json对象,由于有注释的存在则无法正确转换甚至报错. 一下正则表达式 匹配字符串中的所以注释,包括单行和多行注释 复制代码 代码如下: (/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*) 测试地址: http://gskinner.com/RegExr/?30jrh 注意 当使它用作 字符串

  • 强大的Perl正则表达式实例详解

    一.介绍 正则表达式各语言都有自己的规范,但是基本都差不多,都是由元字符的组合来进行匹配:由于Nmap内嵌的服务与版本探测是使用的Perl正则规范,因此此篇博客记录一下Perl正则的相关内容,方便后期查阅. 二.Perl正则例子 下面的例子可能有不足之处,有些来源于博客,没有验证: 1. 匹配IP地址:\d+\.\d+\.\d+\.\d+ \d:匹配一个数字字符,\d+:匹配一次或多次数字字符. \.:使用转义字符匹配'.'. 2. 匹配邮箱类似于123456@qq.com: /^[a-zA-Z

  • 史上最全的PHP正则表达式(手机号需要加上177-***)

    首先看下正则表达式思维导图: 一.校验数字的表达式  1 数字: ^[0-9]*$ 2 n位的数字: ^\d{n}$ 3 至少n位的数字: ^\d{n,}$ 4 m-n位的数字: ^\d{m,n}$ 5 零和非零开头的数字: ^(0|[1-9][0-9]*)$ 6 非零开头的最多带两位小数的数字: ^([1-9][0-9]*)+(.[0-9]{1,2})?$ 7 带1-2位小数的正数或负数: ^(\-)?\d+(\.\d{1,2})?$ 8 正数.负数.和小数: ^(\-|\+)?\d+(\.\

  • JavaScript中正则表达式的概念与应用

    今天和大家分享一些关于正则表达式的知识和在javascript中的应用.正则表达式简单却又不简单,比如以前我的老师给我们讲的时候就说这个东西入门的话二三十分钟就精通了,一旦没有入门那就可几天都补不回来.于是当初就很认真的学习并研究了它.没想到正则表达式不仅代码简洁,而且在实际的操作中为前端工程师们省事了不少.总所周知,用户在浏览页面的时候,唯一和数据打交道的就是表单了,关于表单的验证,其实有很多中方法,接下来,我就会给大家分享两种,一种是普通繁琐的方法,一种是正则表达式,看看它到底能够给表单带来

  • Javascript中正则表达式的使用及基本语法

    前面的话 正则表达式在人们的印象中可能是一堆无法理解的字符,但就是这些符号却实现了字符串的高效操作.通常的情况是,问题本身并不复杂,但没有正则表达式就成了大问题.javascript中的正则表达式作为相当重要的知识,本文将介绍正则表达式的基础语法 定义 正则表达式(Regular Expression)是一门简单语言的语法规范,是强大.便捷.高效的文本处理工具,它应用在一些方法中,对字符串中的信息实现查找.替换和提取操作 javascript中的正则表达式用RegExp对象表示,有两种写法:一种

  • Replace中的正则表达式

    replace:把原有的字符替换成新的字符 1. replace的字符串替换 var str = 'pku2016pku2017'; str = str.replace('pku', 'pkusoft'); console.log(str); // pkusoft2016pku2017 在不使用正则的情况下,每次执行只能替换一个字符,每次执行都是从0开始替换,有重复的,无法全部替换 2. replace的正则的替换 str = str.replace(/pku/g, 'pkusoft'); //

  • 正则表达式中test、exec、match的区别介绍及括号的用法

    test.exec.match的简单区别 1.test test 返回 Boolean,查找对应的字符串中是否存在模式. var str = "1a1b1c"; var reg = new RegExp("1.", ""); alert(reg.test(str)); // true 2.exec exec 查找并返回当前的匹配结果,并以数组的形式返回. var str = "1a1b1c"; var reg = new Re

  • 关于日期正则表达式的思路详解

    1        概述 首先需要说明的一点,无论是Winform,还是Webform,都有很成熟的日历控件,无论从易用性还是可扩展性上看,日期的选择和校验还是用日历控件来实现比较好. 前几天在CSDN多个版块看到需要日期正则的帖子,所以整理了这篇文章,和大家一起讨论交流,如有遗漏或错误的地方,还请大家指正. 日期正则一般是对格式有要求,且数据不是直接由用户输入时使用.因应用场景的不同,写出的正则也不同,复杂程度也自然不同.正则的书写需要根据具体情况具体分析,一个基本原则就是:只写合适的,不写复杂

  • 使用正则表达式验证登录页面输入是否符合要求

    先给大家展示下效果图: 废话不多说了,直接给大家贴代码了,具体代码如下所示: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <script src="js/jquery-1.8.0.min.js"></script> <script> $(f

随机推荐