首页 > 其他 > 详细

[Regular Expressions] Match the Start and End of a Line

时间:2016-02-17 20:57:42      阅读:120      评论:0      收藏:0      [点我收藏+]

We can use:

^: match the beginning
$: match the end

 

Let‘s say we have the string like the following:

var str = `12/1/16
12-16-13
11/12/16
12-12-2016`;

 

What we want to do is get all the ‘12‘ which at the begining of each line:

If we do like that:

var regex = /^12/g;

技术分享

 

To solve this problem, we can use ‘m‘ flag:

var regex = /^12/gm;

技术分享

 

And also we want to get the line which end by ‘16‘:

var regex = /^12.+16$/gm;

技术分享

[Regular Expressions] Match the Start and End of a Line

原文:http://www.cnblogs.com/Answer1215/p/5196455.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!