私は、以下のように複数のリンク文字列を持つ文字列を持っている状況があります。場合文字列を置換するためにJavascriptまたはLodashを使用してください
http://www.testing.com Simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap https://asdfasdf.com
私は「HTTP」が発生したことをどこでものインデックスを取得するには、以下の機能を使用していますが、知りたいと思った:例テキスト<a href=”http://www.testing.com” target=_blank>http://www.asdfasd.com</a>
:私は、実際のリンクなどとのリンクを交換する必要がありますより簡単な方法があります。
indexes(comments.Answers, "http");
function indexes(source, find) {
var result = [];
for (var i = 0; i < source.length; ++i) {
// If you want to search case insensitive use
// if (source.substring(i, i + find.length).toLowerCase() == find) {
if (source.substring(i, i + find.length) == find) {
result.push(i);
}
}
console.log("result ", result);
return result;
}
提供したソーステキストには「http」のインスタンスはありません。あなたがしようとしていることをもっと明確にすることができますか? RegExが可能な解決策であるようです。 – dave
ええ、単に 'str.replace(/www.testing.com/gi、 '$1')'を実行してみませんか? –
URLの内容がわかりません。テキストはクライアントによって提供され、URLの自動フォーマットが必要です –