2017-01-22 5 views

答えて

1

negated character classと、次の正規表現を使用します。その+(またはenything | regex.exec(文字列)と

var s = "[hello world](one two)"; 
 
var x = s.replace(/\[([^\]]*)]\(([^)]*)\)/, '<p>$1</p><b>$2</b>'); 
 

 
console.log(x);

Regex explanation here.

+0

これは私の答えよりもはるかに安全です。逆チャートクラスを使用すると、空の文字列を許可しない理由はありません。私は+をa *に置き換えます。 – till

+0

@till:ありがとう、私はちょうどそれを更新:) –

2

console.log("[hello world](one two)".replace(/\[(.*)\]\((.*)\)/, '<p>$1</p><b>$2</b>'));

0

使用キャプチャグループと、この((())()[。]。)これに似ています)、オオプシュット文字列を作成します。

関連する問題