| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx

javascript正则表达式语法教程大全

-1
JavaScript Python Java C/C++ Go 21216 次浏览

javascript开发中,正则表达式是字符一个特殊的序列,它被广泛应用与python开发世界中。

今天小编主要给大家介绍javascript正则表达式的语法,并进行了整理汇总,需要的朋友可以参考下正则表达式语法实用功能。

1、匹配中文字符的正则表达式: [\u4e00-\u9fa5]

评注:匹配中文还真是个头疼的事,有了这个表达式就好办了

2、匹配双字节字符(包括汉字在内)[^\x00-\xff]

评注:可以用来计算字符串的长度(一个双字节字符长度计2ASCII字符计1

3、匹配空白行的正则表达式:\n\s*\r

评注:可以用来删除空白行

4、匹配HTML标记的正则表达式:<(\S*?)[^>]*>.*?</\1>|<.*? />

评注:网上流传的版本太糟糕,上面这个也仅仅能匹配部分,对于复杂的嵌套标记依旧无能为力

5、匹配首尾空白字符的正则表达式:^\s*|\s*$

评注:可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式

6、匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

评注:表单验证时很实用

7、匹配网址URL的正则表达式:[a-zA-z]+://[^\s]*

评注:网上流传的版本功能很有限,上面这个基本可以满足需求

8、匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线)^[a-zA-Z][a-zA-Z0-9_]{4,15}$

评注:表单验证时很实用

9、匹配国内电话号码:\d{3}-\d{8}|\d{4}-\d{7}

评注:匹配形式如 0511-4405222  021-87888822

10、匹配腾讯QQ号:[1-9][0-9]{4,}

评注:腾讯QQ号从10000开始

11、匹配中国邮政编码:[1-9]\d{5}(?!\d)

评注:中国邮政编码为6位数字

12、匹配身份证:\d{15}|\d{18}

评注:中国的身份证为15位或18

13、匹配ip地址:\d+\.\d+\.\d+\.\d+

评注:提取ip地址时有用

14、匹配特定数字:

^[1-9]\d*$    //匹配正整数

^-[1-9]\d*$   //匹配负整数

^-?[1-9]\d*$  //匹配整数

^[1-9]\d*|0$  //匹配非负整数(正整数 + 0

^-[1-9]\d*|0$  //匹配非正整数(负整数 + 0

^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$  //匹配正浮点数

^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$  //匹配负浮点数

^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$  //匹配浮点数

^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$  //匹配非负浮点数(正浮点数 + 0

^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$ //匹配非正浮点数(负浮点数 + 0

评注:处理大量数据时有用,具体应用时注意修正

15、匹配特定字符串:

^[A-Za-z]+$ //匹配由26个英文字母组成的字符串

^[A-Z]+$ //匹配由26个英文字母的大写组成的字符串

^[a-z]+$ //匹配由26个英文字母的小写组成的字符串

^[A-Za-z0-9]+$ //匹配由数字和26个英文字母组成的字符串

^\w+$ //匹配由数字、26个英文字母或者下划线组成的字符串

评注:最基本也是最常用的一些表达式

以上就是对javascript正则表达式语法的汇总,相信看了这么多以后,让你对javascript正则表达式的用法有了进一步的了解,若还有不懂的朋友,可以搜索麦子学院,可以看到更多相关视频教程。

 

37个答案

0

slot 666Online slot web ready to provide entertainment on the internet 666 slot

0

สล็อต โรม่าRoma slot, the most popular online slot game of all time, roma slot 888, play free, online roma slot game. playing for real money Legendary online gambling game 2021 Roma Slots from famous gaming companies

0

SLOTA very popular game camp that played many years ago. Until now because it's a simple game. The rules are not complicated, the game is played for fun.

0

พีจีสล็อตonline slot games Deposit-withdraw via automatic system It has been ranked number 1 in popularity right now and is the most popular slot website right now.

0

pg slot autoBig web slots, PG, direct websites, not through agents 2021 with a fast automatic deposit-withdrawal system within 8 seconds.

0

ทางเข้าpg It is a new hot new game camp of the year 2021, in which this camp pg 168 is very different from other camps and one of them is clearly Pc game 168.

0

The Yaamava’ is located in Highland, CA, and is owned ซุปเปอร์ สล็อต by the San Manuel Band of Mission Indians.

0

slot 1234   Earn real money without investment 2021 new dimension of making money from online gambling games Play free fish shooting games.

0

ฝาก50รับ150   Deposit 50, get 150, no need to turn or call it easy to understand is a promotion, deposit 50, get 150 wallet as another

0

ฝาก20รับ100  A promotion that many people like and think that it is a worthwhile promotion.

0

ฝาก30รับ100   Latest 2021 Promotion Hits Slots Can play all game camps, new members, deposit 30, get 100, give away free credit, no need to deposit, no need to share Promotion deposit 30 get 100 unlimited withdrawal No minimum deposit

0

pg slot เว็บใหม่  The hottest slot game camp now in 2021, including all slots, all game camps in one website, welcomes PG, a new website, free credit, no deposit required, easy to play, earn real money.

0

Super Slot 888   The number 1 online slot game in Thailand, slot 888 online that includes the slot 888 game camp to play more than 300 games, slot 888 auto, open for deposit-withdrawal service with an automatic system.

0

เล่นสล็อต   Free Trial PG and Joker is to play slots for free without having to pay a deposit first. There are currently playing slots. mostly through the mobile internet without having to go to the casino to play slots

0

โปรโมชั่นสล็อต  Promotion of new web slots 2021 that is becoming popular right now. inevitable promotion New member 100% bonus

0

ไฮโลSlot games from the popular roma xo slots and free roma credit slots 2021 You can try it for free now.   Slot games from the popular roma xo slots and free roma credit slots 2021 You can try it for free now.

0

เกมยิงปลา  Earn real money without investment 2021 new dimension of making money from online gambling games Play free fish shooting games.

0

pg game  online slot games Which is popular as No. 1 now, deposit-withdraw via the auto system.

0

ทดลองเล่นสล็อต  Slots Free Trial Playable Withdrawable Free Trial Playable Withdraw Real Money Free credit to play slots Terms and conditions are as specified by the website.

0

สล็อต 888  The number 1 online slot game in Thailand, slot 888 online that includes the 888 slot game camp to play more than 300 games.

1 2