All single uppercase/lowercase letters, numbers, and special characters to be described later are a regular expression. They can only match a single character, and this character is the same as itself. For example, for the expression "I ":
welcome to visit www.bkjia.com
The following applet will match the lower-case letter I in the string welcome to visit www.bkjia.com, replace it with the upper-case letter I, and change the background color to orange.
Effect demonstration
Welcome to visit www.bkjia.com
Welcome to visit www.bkjia.com
Program code:
<script type="text/javascript">function reg_replace(){var str = "welcome to visit www.bkjia.com";var test = document.getElementById("test");regex = new RegExp("i","g");test.innerHTML = str.replace(regex,"<span style='background-color:orange'>I</span>");//alert(str.replace(regex,"I"));}function reg_split(){var str = "welcome to visit www.bkjia.com";var test = document.getElementById("split");regex = new RegExp("i","g");test.innerHTML = str.split(regex);//alert(str.replace(regex,"I"));}</script>
A combination of multiple fixed characters constitutes an expression that matches a fixed string. For example, "bkjia" is also a regular expression, which consists of multiple expressions that match a fixed character. It can only match any text exactly the same as it:
Effect demonstration
Welcome to visit www.bkjia.com
You can understand the matching process of the expression "bkjia" as follows: it consists of n, o, w, a, m, a, g, I, c is a fixed string of 9 characters. For each character, it can only match exactly the same character. When these 9 characters are combined, it matches the character string in the same order as the expression and at the same position as the corresponding character (in fact, it is a string exactly the same as the expression ).
Because this matching method is the least flexible, it can only match exactly the same characters, so it is also called "full match ".
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