初学JavaScript正则表达式(一)

给单个单词is改为大写的IS

is        //  指的是单词边界

IS
He is a boy
        
This is a test
        
isn't it

 

给以http://开头并且以jpg结尾的链接删除掉http://

//   //要分别通过转义字符转义    第一个.指的是任意字符   第二个点用其本意,需要用转义字符转义

http://(.+.jpg)    

$1
http://img.host.com/images/djkahdjas.jpg
        
https://img.host.com/images/djkahdjas.png
        
http://img.host.com/images/djkahdjas.png
        
https://img.host.com/images/djkahdjas.png
        
http://img.host.com/images/djkahdjas.jpg
        
https://img.host.com/images/djkahdjas.jpg

 

将“年(-/)月(-/)日”类型改为“月-日-年”类型

^代表起始位置   $代表终止位置   d代表数字   d{4}代表四个数字    [-/]代表-或/   ()代表分组
第一个()即为$1  第二个()即为$2   以此类推

^(d{4})[-/](d{2})[-/](d{2})$

$2-$3-$1
1998-05-12
        
1999/06/06
        
1786/05-02
        
125896/03/06
        
2587-06-08

整理自慕课网教学 点此进入

博主信息:

昵称:HamyFrank

网站:我的网站

邮箱: xueshuai_12@163.com

QQ:246776020

QQ群:1063233592

WeChat:js_cool_100

原文地址:https://www.cnblogs.com/xue-shuai/p/12000626.html