2016-11-21 9 views
-1

私はリンクを含む文字列変数を他のテキストの中に入れています。特定の顧客を含むすべてのリンクを抽出できます。 ...これは可能ですか?Googleのアプリケーションスクリプトで文字列のすべてのリンクを抽出します。

変数の文字列のようなものです。内容として文字列を使用して文書を作成するために、extract links from documentして、リンクを抽出し、しかし、私はやりたい:回避策として

var string = 'here is some text line among the ones there will be links like https://stackoverflow.com/questions/40725199/extract-all-links-from-a-string-with-google-app-script?noredirect=1#comment68679843_40725199 and more'; 

、私はここで説明したものを使用しましたそれを直接...

よろしく、(ルーベンへ)

EDIT:

私が使用している場合:

var string = 'http://mangafox.me/manga/tales_of_demons_and_gods/c105/1.html here is some text line among the ones there will be links like https://stackoverflow.com/questions/40725199/extract-all-links-from-a-string-with-google-app-script?noredirect=1#comment68679843_40725199 and more '; 

私は最初のリンクを2回だけ取得しました(スクリーンショットhereを参照)。

と私が使用している場合:

var string = 'here is some text line among the ones there will be links like https://stackoverflow.com/questions/40725199/extract-all-links-from-a-string-with-google-app-script?noredirect=1#comment68679843_40725199 and more http://mangafox.me/manga/tales_of_demons_and_gods/c105/1.html '; 

同じ再び(screenshoot hereを参照してください)。

+0

あなたが "内部リンクを含む文字列変数" とはどういう意味ですか?彼らはURLですか?サンプルの文字列を含めて、あなたが意味するものを明確にすることができます。何を試しましたか? –

+0

可変文字列は次のようなものです: var string = 'ここには、http://stackoverflow.com/questions/40725199/extract-all-links-from-a-string-withのようなリンクがあります。 -google-app-script?noredirect = 1#comment68679843_40725199以上 '; –

答えて

1

Google Appsのスクリプト

function test2(){ 
    var re = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'"".,<>?«»“”‘’]))/i; 
    var string = 'here is some text line among the ones there will be links like https://stackoverflow.com/questions/40725199/extract-all-links-from-a-string-with-google-app-script?noredirect=1#comment68679843_40725199 and more'; 
    for(var i = 0; i <= re.exec(string).length; i++){ 
    if(re.exec(string)[i]) Logger.log(re.exec(string)[i]) 
    } 
} 

JavaScriptを。

var re = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'"".,<>?«»“”‘’]))/i; 
 
var string = 'here is some text line among the ones there will be links like https://stackoverflow.com/questions/40725199/extract-all-links-from-a-string-with-google-app-script?noredirect=1#comment68679843_40725199 and more here is some text line among the ones there will be links like https://stackoverflow.com/questions/40725199/extract-all-links-from-a-string-with-google-app-script?noredirect=1#comment68679843_40725199 and more'; 
 
for(var i = 0; i <= re.exec(string).length; i++){ 
 
    if(re.exec(string)[i]) console.log(re.exec(string)[i]) 
 
}

リファレンス

RegularExpression to Extract Url For Javascript

+0

こんにちは、ありがとうございます!何らかの理由で私は文字列内の最初のリンクしか取得しません。それらのすべてを得る方法はありますか? –

+0

詳細を追加してください。 –

+0

[OK]を、私はこの文字列にあなたの更新版を使用しました: 'http://mangafox.me/manga/tales_of_demons_and_gods/c105/1.html http://stackoverflow.com/questions/40725199/extract-all-links- google-app-script/40728530?noredirect = 1#comment68918084_40728530ここにはテキスト行があります。http://stackoverflow.com/questions/40725199/extract-all- google-app-scriptを使ったリンクからのリンク?noredirect = 1#comment68679843_40725199などhttp://mangafox.me/manga/tales_of_demons_and_gods/c105/1.html '; –

関連する問題