Home Web Front-end JS Tutorial Solve js regular matching line break problem implementation code_Basic knowledge

Solve js regular matching line break problem implementation code_Basic knowledge

May 16, 2016 pm 05:47 PM
match newline

Copy code The code is as follows:

<div id="main">
<div id=”left”>
</div>
<div id=”right”>
php
</div>
</ div> >
The code is as follows:


<div id="main">
<div id="left"></div>
<div id="right"> php </div> </div> If you use JS to write it, how should you write it?
The correct code for JS is as follows:
HTML code:




Copy code

The code is as follows:


<script type="text/javascript">
function getV(){
var str=document.getElementById("regtext").value; var re=/([nr ])(s)*(</div>?(s)*<div) /g; str=str.replace(re,"$3"); alert(str); } </script> <textarea id="regtext" cols="20" rows="20">
<div id="main">
&lt ;div id="left">
</div>
<div id="Div1">
</div>
<div id="Div2"&gt ;
</div>
<div id="right">
php
</div>
</div>
</textarea>
<input type="button" onclick="getV()" value="Test" />


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Practical Guide to Regular Expressions in Go: How to Match Hexadecimal Color Codes Practical Guide to Regular Expressions in Go: How to Match Hexadecimal Color Codes Jul 13, 2023 am 10:46 AM

Practical Guide to Regular Expressions in Go: How to Match Hexadecimal Color Codes

PHP regular expressions: exact matching and exclusion of fuzzy inclusions PHP regular expressions: exact matching and exclusion of fuzzy inclusions Feb 28, 2024 pm 01:03 PM

PHP regular expressions: exact matching and exclusion of fuzzy inclusions

How to wrap lines in BarTender - How to wrap lines in BarTender How to wrap lines in BarTender - How to wrap lines in BarTender Mar 05, 2024 pm 07:52 PM

How to wrap lines in BarTender - How to wrap lines in BarTender

PHP regular expression in action: matching letters and numbers PHP regular expression in action: matching letters and numbers Jun 22, 2023 pm 04:49 PM

PHP regular expression in action: matching letters and numbers

How to wrap rows in excel table How to wrap rows in excel table Feb 09, 2024 pm 02:00 PM

How to wrap rows in excel table

How to wrap cells in Excel on Apple computers How to wrap cells in Excel on Apple computers Feb 18, 2024 pm 08:39 PM

How to wrap cells in Excel on Apple computers

How to wrap line on iPhone? How to set line wrap on iPhone? How to wrap line on iPhone? How to set line wrap on iPhone? Mar 22, 2024 pm 06:50 PM

How to wrap line on iPhone? How to set line wrap on iPhone?

PHP String Matching Tips: Avoid Ambiguous Included Expressions PHP String Matching Tips: Avoid Ambiguous Included Expressions Feb 29, 2024 am 08:06 AM

PHP String Matching Tips: Avoid Ambiguous Included Expressions

See all articles