We can use:

^: match the beginning
$: match the end

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

var str = `//
--
//
--`;

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

If we do like that:

var regex = /^/g;

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

var regex = /^/gm;

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

var regex = /^.+$/gm;

[Regular Expressions] Match the Start and End of a Line的更多相关文章

  1. [Regular Expressions] Match the Same String Twice

    Regular Expression Backreferences provide us a method to match a previously captured pattern a secon ...

  2. PCRE Perl Compatible Regular Expressions Learning

    catalog . PCRE Introduction . pcre2api . pcre2jit . PCRE Programing 1. PCRE Introduction The PCRE li ...

  3. 8 Regular Expressions You Should Know

    Regular expressions are a language of their own. When you learn a new programming language, they're ...

  4. Regular Expressions --正则表达式官方教程

    http://docs.oracle.com/javase/tutorial/essential/regex/index.html This lesson explains how to use th ...

  5. Regular Expressions in Grep Command with 10 Examples --reference

    Regular expressions are used to search and manipulate the text, based on the patterns. Most of the L ...

  6. [Regular Expressions] Introduction

    var str = "Is this This?"; //var regex = new RegExp("is", "gi"); var r ...

  7. Introducing Regular Expressions 学习笔记

    Introducing Regular Expressions 读书笔记 工具: regexbuddy:http://download.csdn.net/tag/regexbuddy%E7%A0%B4 ...

  8. [转]8 Regular Expressions You Should Know

    Regular expressions are a language of their own. When you learn a new programming language, they're ...

  9. 正则表达式(Regular expressions)使用笔记

    Regular expressions are a powerful language for matching text patterns. This page gives a basic intr ...

随机推荐

  1. [Regular Expressions] Introduction

    var str = "Is this This?"; //var regex = new RegExp("is", "gi"); var r ...

  2. 杭电 HDU ACM Milk

    Milk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  3. Canvas制作排序算法演示动画

    tips: 形象化演示排序算法可以让初学者快速理解,比较好的例子:jun-lu的SortAnimate,旧金山大学的David Galles教授的算法演示课件.最近在看canvas,试着用js+can ...

  4. VCS仿真生成fsdb文件(Verilog)

    VCS仿真生成fsdb文件(Verilog) 一.环境 Linux 平台 csh环境 VCS 64bit Verdi3 二.开始仿真 1. 联合仿真环境配置 a.在testbench中加入如下语句: ...

  5. css_day7

  6. asp.net实现将网页内容输出到word并下载到本地

    个人觉得要实现这个功能如果没有类库提供的几个关键函数,还是比较繁琐的.所以首先介绍几个将要在代码中使用的关键函数和参数,然后再说函数实现.注意问题等. 关键函数: 1.函数原型:Response.Ap ...

  7. java.sql.SQLException: ORA-00911: 无效字符 解决方案

    在使用java执行sql时,抛出的这样一个Oracle异常,最后发现是sql语句末尾有一个分号导致,例如:sql="select * from tl_demo;" .删除" ...

  8. IE6 浏览器常见兼容问题 大汇总(23个)

    IE6以及各个浏览器常见兼容问题 大汇总 综述:虽然说IE6在2014年4月将被停止支持,但是不得不说的是,IE6的市场并不会随着支持的停止而立刻消散下去,对于WEB前端开发工程师来说,兼容IE6 兼 ...

  9. Oracle 批量操作

    背景: 前两天由于工作需要做个业务单据接口(支持批量处理),一般有接口发布为批量,但访问数据库时还是一张张单据处理,本次访问数据库也是批量操作.   内容: 研究发现Oracle批量操作有两种:1)B ...

  10. HTTP get、post请求

    Post请求: string postData = "user=123&pass=456"; // 要发放的数据 byte[] byteArray = Encoding.U ...