LoginSignup
0
0

More than 3 years have passed since last update.

javascript 正規表現で置換 str replace

Last updated at Posted at 2020-10-27

javascriptで正規表現をやりたい
text.replace("/<p>/","");
マッチング部分を " で囲むとバグるので注意


var text = 'youryour';


//文字列置換 (各最短マッチ)
var tmp = text.replace(/<p>|<h3>|<blockquote.*?<\/blockquote>|<img.*?>|<iframe.*?<\/iframe>|<code.*?<\/code>|<pre.*?<\/pre>/gsim, '');

//</p> もしくは </h3> を改行に変換
var tmp = tmp.replace(/<\/p>|<\/h3>/gsim,"\n");

修飾子の意味

m : 複数行検索
s : を改行文字と一致するようにします。
i : 大文字、小文字の区別をしない
g : 最初にマッチした時点でマッチする文字列を探すのを終了せず全てのマッチする文字列を探します。複数マッチングするかを調べることができます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0