2016-07-25 3 views
-1

私はHTMLを含む文字列を持っています。私はスペースでこの文字列を分割したいが、私はHTMLをしたくない。例えばjavascript regexはスペースとhtmlで分割されています

scrambled it to make a type specimen book. It <a href="http://php.net/manual/en/function.sprintf.php">http://php.net/manual/en/function.sprintf.php</a> some more text. 

それは半分にアンカータグをカットスペースで文字列をスリット。 <a>タグまたは<br>タグを1つの単語と見なしたいと思います。

+0

String.prototype.match()を使用することができますが、あなたが 'html'文字列内のノードを反復処理しようとしたことがありますか? – guest271314

答えて

1

あなたはRegExp/\w+|<a\s.*\/a>|(<br>|<br\s\/>|<br\/>)/g

var str = `scrambled it to make 
 
<br> a type specimen book. 
 
<br/> It 
 
<a href="http://php.net/manual/en/function.sprintf.php"> 
 
http://php.net/manual/en/function.sprintf.php 
 
</a> 
 
<br /> some more text.`; 
 

 
console.log(str.match(/\w+|<a\s.*\/a>|(<br>|<br\s\/>|<br\/>)/g));

関連する問題