1
正規表現によるハッシュ値を呼び出す:Javascriptを - 次のように私は、コードを持っている派生キー
var str =
`<doc>
<a href="#h-1">
<a href="#h-2">
<a href="#h-3">
</doc>
<doc>
<a href="#h-9">
</doc>`
var veg_anchor_map = new Object();
veg_anchor_map['h-1'] = 'cabbage';
veg_anchor_map['h-2'] = 'potato';
veg_anchor_map['h-3'] = 'carrot';
var href_regex = /<a href="#(.*?)"/g;
str = str.replace(href_regex, veg_anchor_map['$1']);
console.log(str);
私はこの構文に私のstr変数内のすべてのhrefのリンクを交換しようとしている:
//example:
<doc>
cabbage>;
potato>;
carrot>;
</doc>
しかし、私は正規表現の文でグルーピングを呼び出そうとするたびに、それは未定義であると誰も私にこれを手伝うことができますか?ありがとうございました。コールバック機能付き
ありがとうございました、統合されていると完璧に動作します! – Basque0407
@ Basque0407、大歓迎です – RomanPerekhrest