The difference between g mode and non-g mode using regular expressions in JS. js Regular Expressions
First, Let's explain what g in the js regular expression actually means.
G is short for global!
That is, matching all matching results,
If you do not include g, the string is matched from left to right during the regular expression process. If the match is successful, the string will not be matched to the right. If you do not include g, it selects the correct matching string from the beginning to the end.
For example:
Var str = 'aaaaaaa' var reg1 =/a/var reg2 =/a/gstr. match (reg1) // The result is: ["a", index: 0, input: "aaaaaaaa"] str. match (reg2) // The result is: ["a", "", "a"]
The difference between the js Regular Expression g mode and the non-g mode is as follows:
<! DOCTYPE html>
The above section describes the differences between the regular expression g mode and the non-g mode in JS. I hope it will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!