Regular Expression Word Boundaries allow to perform "whole word only" searches within our source string.

 Imaging we have string as follow, and we want to match all the string which start by 'is:'
var str = `This history is his, it is`;

The easiest way is using : \b

\b  //catch the whole word;
\bis // catch the 'is', which in the beginning of the word
is\b // catch the 'is', which in the end of the word
\bis\b //catch only 'is', with nothing else

Catch start with 'is':

var regex = /\bis/g

Catch end with 'is':

var regex = /is\b/g

Catch only 'is':

var regex = /\bis\b/g

Also '\B' has the oppset meanings with '\b':

\Bis  // catch 'is', which is NOT at the beginng
is\B // catch 'is', which is NOT at the end
\Bis\B //catch 'is', which it neither at beginng or end

Not at the begining:

var regex = /\Bis/g

Not at the end:

var regex = /is\B/g

Neither begining nor end:

var regex = /\Bis\B/g

The same effect as previous one.

[Regular Expressions] Find the Start and End of Whole Words的更多相关文章

  1. PCRE Perl Compatible Regular Expressions Learning

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

  2. 8 Regular Expressions You Should Know

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

  3. 转载:邮箱正则表达式Comparing E-mail Address Validating Regular Expressions

    Comparing E-mail Address Validating Regular Expressions Updated: 2/3/2012 Summary This page compares ...

  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] Find Plain Text Patterns

    The simplest use of Regular Expressions is to find a plain text pattern. In this lesson we'll look a ...

  7. [Regular Expressions] Introduction

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

  8. Introducing Regular Expressions 学习笔记

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

  9. [转]8 Regular Expressions You Should Know

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

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

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

随机推荐

  1. MySql查看表信息

    SELECT TABLE_NAME, TABLE_COMMENT -- 指定信息列 FROM `information_schema`.`tables` A WHERE A.`TABLE_SCHEMA ...

  2. [.NET | 發佈] 如何指定固定的目錄給程式調用的外部DLL?

    1.OverView 一般程式只會查找與主程式同目錄的DLL檔案 解決方案主要可以參考這篇:http://support.microsoft.com/kb/837908 2.實作app.config方 ...

  3. C# 大小写转换

    全部大写: string upper = str.ToUpper() 全部小写: string lower = str.ToLower(); str是需要转换的字符.

  4. javascript将毫秒还原为可读时间格式

    <script type="text/javascript"> //随便设置一个时间 var otime = new Date("2015-11-11 20: ...

  5. Ztree中simpleData是怎么转换成标准ztree数组对象的

    今天遇到一个自己构造树的情况,树是动态的,预先不知道根节点,用的是easyUI中的tree,于是参考了下Ztree中的实现,恍然大悟,遂记之: transformTozTreeFormat: func ...

  6. 函数:我的地盘听我的 - 零基础入门学习Python019

    函数:我的地盘听我的 让编程改变世界 Change the world by program 函数与过程 在小甲鱼另一个实践性超强的编程视频教学<零基础入门学习Delphi>中,我们谈到了 ...

  7. Javascript个人理解

    一. 生成对象的原始模式 假定我们把猫看成一个对象,它有"名字"和"颜色"两个属性. var Cat = { name : '', color : '' } 现 ...

  8. EF查询

    public ActionResult AllSettings(DataSourceRequest command, Framework.Kendoui.Filter filter = null, S ...

  9. sqlserver中临时表、row-number、update更新自己

    SELECT * INTO #TempStudent FROM (SELECT id, ROW_NUMBER() OVER(ORDER BY id) RowNum FROM dbo.student) ...

  10. 开发中遇到的问题(一)——java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

    1.错误描述: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) wit ...