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. Label 表达式绑定

    Text='<%#"总金额为: "+Convert.ToString(Convert.ToDecimal(TextBox1.Text)*Convert.ToInt32(Tex ...

  2. Java 访问控制符

    Java提供了3个访问控制符:private.protected和public,分别代表了3个访问控制级别,另外还有一个不加任何访问控制符的访问控制级别,提供了4个访问控制级别.Java的访问控制级别 ...

  3. iOS_SN_深浅拷贝( 百度的)_转载

    文章原地址:http://www.cnblogs.com/5ishare/p/4362459.html 深浅拷贝前提是:是实现NSCopying或者NSMutableCopying协议. 浅拷贝只是复 ...

  4. c#中serialPort1_DataReceived串口接收事件处理

    1.缓冲区不定字节读取(波特率很高也没问题) //Thread.sleep(1000);//处理事件这块可以加上延时确保不定数的数据可以全部收到缓冲后,才去读缓冲内容--单位:毫秒 byte[] da ...

  5. Mysql学习(慕课学习笔记7)修改数据表(下)

    添加主键约束 ALTER TABLE tb1_name ADD [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name,…….) ...

  6. linux for循环

    一定要记得写后面的分号:http://www.runoob.com/linux/linux-shell-variable.html 这个页面的课程的循环教程是有问题的 for color in yel ...

  7. ubuntu 下使用mysql

    第一步:安装mysql apt-get install mysql-server 第二步:设置允许远程登录 修改/etc/mysql/my.cnf(此文件为mysql的配置文件).将文件中的bindi ...

  8. 使用ES6进行开发的思考

    ECMAScript6已经于近日进入了RC阶段,而早在其处于社区讨论时,我就开始一直在尝试使用ES6进行开发的方案.在Babel推出后,基于ES6的开发也有了具体可执行的解决方案,无论是Build还是 ...

  9. JS+css滑动菜单简单实现

    JS+css滑动菜单 制作一个简单的滑动菜单,当鼠标指向菜单标题时,滑出二级菜单.移开时二级菜单隐藏.目标很简单,实践时有一些细节需要注意,比如鼠标移向二级菜单的 过程中,二级菜单消失了.还有定位出错 ...

  10. show,hide与fadeIn、fadeOu的区别

    show,hide——>是通过改变height,width,opacity来实现动画的显示与隐藏的 fadeIn.fadeOut——>只通过opacity来实现动画的显示与隐藏的 它们两个 ...