This paper analyzes the Single-line mode and multiline pattern in JS regular expression. Share to everyone for your reference. Specifically as follows:
JS Regular expressions are not supported in Single-line mode. That is, you cannot take a piece of content (there is a newline), using a pattern modifier to deal with the whole piece of content as a line to deal with.
For regular multiline substitution, you need to add the/mg pattern enhancer.
Copy Code code as follows:
<script type= "Text/javascript" >
/ /Regular replacement link, Link has newline
Function T1 () {
var con = document.getelementsbyname (' content ') [0].value;//content <a "" >.....</a>, but there are newline
var reg =/<a[\s]+[\d\d]*<\/a>/g;//use [\d\d] or [\w\w] or [\s\s] To resolve a problem that cannot be wrapped
alert (Con.replace (Reg, '----'));
}
//The ending number of each row is replaced with the # number---Multiline mode, add/m (end of each line) and/g (global match) pattern enhancer
Function t2 () {
var con = document.gete Lementsbyname (' content ') [0].value;//writes several lines of text, each line ends with a number
var reg =/\d+$/gm;
alert (Con.replace (Reg, ' # '));
}
</script>
<body>
<textarea rows= "5" cols= "a" name= "content" &G t;</textarea><br/>
<button onclick= "T1 ();" > Regular replacement links (to be considered for line wrapping) </button><br/>
<button onclick= "T2 ();" > Regular multiple-line replacement </button><br/>
</body>
I hope this article is helpful to the regular expression learning.