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. 解决 Google 重定向,体验 Google 本味

    想要体验原汁原味的 Google(google.com),下面的方案是我用过的较方便的方案. 欢迎更正及补充 Chrome 扩展 Chrone 商店有一款禁止重定向的扩展 NoCountryRedir ...

  2. let关键字

    作用: 与var类似, 用于声明一个变量特点: 只在块作用域内有效 不能重复声明 不会预处理, 不存在提升应用: 循环遍历加监听 //应用实例 <body> <button>测 ...

  3. Asp.net原理(第一篇)

    Asp.net (第一篇) 当用户在浏览器输入一个URL地址后,浏览器会发送一个请求到服务器.这时候在服务器上第一个负责处理请求的是IIS.然后IIS再根据请求的URL扩展名将请求分发给不同的ISAP ...

  4. ubuntu中安装Docker

    系统要求: 必须时64位的系统,内核最低要求是3.10 查看系统内核: $ uname -r 3.11.0-15-generic 获取最新版本打Docker: $ wget -qO- https:// ...

  5. Javascript实现表格行排序

    网站开发中凡是用到表格来展示数据的,往往都要根据某个列来对行排序,下面是我从书上看到的一个行排序例子,看过后受益匪浅,故分享出来. 直接献上完整代码: <!doctype html> &l ...

  6. centos打开3306端口

    centos默认是关闭了3306端口的,外网通过3306端口不能访问数据库,这时需呀打开3306端口1.打开端口: /sbin/iptables -I INPUT -p tcp --dport 330 ...

  7. UISearchDisplayController简单使用

    最近在做一个简单的app入门,中间有一个页面用到了搜索框,本来以为很简单的控件,没想到用到的时候才发现很麻烦. 搜索框使用过程大约有以下几个状态:不活跃-活跃-输入关键词-根据关键词动态列出相关结果- ...

  8. (三)CodeMirror - Event

    "change" (instance: CodeMirror, changeObj: object) { from, // object to, // object text, / ...

  9. CI框架uri去掉index.php

    CI框架的入口是index.php,所以url实际上要多出一个index.php,非常不美观.我使用的是apache服务器,要开启mod_rewrite服务才可以. sudo a2enmod rewr ...

  10. ajax请求参数为中文乱码的情况

    解决中文乱码问题的方法有很多. 一.前提是ajax请求传递参数对象到后台,对象中的某个参数的值为中文,到后台之后出现乱码,导致报错.问题解决如下: rest层: 二.在tomcat的server.xm ...