It is somewhat similar to matching a specific type of character. With "\ B", there is naturally "\ B", which is used to match characters that are not at the boundary.
We will continue to take the above example for demonstration to see the matching effect of "\ Bmagic:
The regular expression is as follows:
\Bmagic
Effect demo welcome to bkjia this magic place!
This example code
function reg_replace(){var test = document.getElementById("test");var regex = /\B(magic)/g;test.innerHTML = test.innerHTML.replace(regex,"<span style='background-color:orange'>$1</span>");}
Its matching rules are as follows: the character "m" must appear, but cannot be at the top of the string; followed by two fixed characters a, g, I, c.
Let's extend the above example: \ Bmagic \ B
It can match magic in bkjias, and cannot be a null character before or after magic.
Additional reading
The topic list of this article is as follows:
- What is a regular expression?
- Getting started with regular expressions: match a Fixed Single Character
- Getting started with regular expressions: matching any single character
- Getting started with regular expressions: Use character groups
- Getting started with regular expressions: Use character ranges in character groups
- Getting started with regular expressions: Use of assense character groups
- Getting started with regular expressions: matching null characters
- Getting started with regular expressions: Match one or more characters
- Regular Expression: matches zero or multiple characters.
- Regular Expression entry: matches zero or one string.
- Getting started with regular expressions: Match fixed numbers of Characters
- Getting started with regular expressions: match the number of characters in a range
- Getting started with regular expressions: greedy matching
- Getting started with regular expressions: inert matching
- Entry to Regular Expressions: two matching Modes
- Getting started with regular expressions: match word boundaries
- Getting started with regular expressions: boundary definition and relativity
- Getting started with regular expressions: Match non-word boundaries
- Getting started with regular expressions: match the beginning and end of a text
- Entry to regular expression: submode
- Regular Expression entry: "or" Match
- Getting started with regular expressions: replacing with referenced text
- Getting started with regular expressions: unmatched
- Regular Expression Summary: Regular Expressions in JavaScript
- Regular Expression Summary: advanced application of regular expressions in js