We know that whether it is using "bkjia [0-3] \. net "or" bkjia [^ 0-3] \. net, bkjia, and. ". net" always has one character, and sometimes we allow them to not appear between them. For example, if I want to match "bkjia.com", then, how can this be done?
In a regular expression, it can be in a single character (such as "j"), a character group (such as "[abcde]"), or a specific character type (such as "\ d "), any character (that is, ". ") followed by" * "to indicate matching strings composed of zero or multiple characters. It can be seen that the method used is exactly the same as "+.
For the above example, we can write the following expression:
bkjia\d*\.net
Effect demonstration
Www.bkjia2.net
Www.bkjia.com
Www.bkjia1.net
This example code
function reg_replace(){var test = document.getElementById("test");aim = "bkjia\d*\.net";var regex = new RegExp("("+aim+")","g");test.innerHTML = test.innerHTML.replace(regex,"<span style='background-color:orange'>$1</span>");}
The expression "bkjia \ d *\. net "matches a string like this: It starts with" bkjia ", followed by zero or more" 0-9 "numeric characters, and then starts with".. net.
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