2017-02-18 2 views
1

私はすべてのタグの中のすべての文字と単語( "...")を特定のパターン、例えば/desktop/contentから始まるselectパターンで選択するためにregexを使用しようとしています。regexで特定のパターンですべてのURLを選択する

これはかなりシンプルですが、自分ではできないと思いますが、誰かを助けることができますか?

例:

<img src="/desktop/content/img/illustrations/small-flower2.svg" width="138"/> 

選択された部分は次のようになります。/desktop/content/img/illustrations/small-flower2.svg

答えて

1

あなたは/"someQuotedString([^"]*)"/gmのような正規表現を意味ですか?

var str = '<img src="/desktop/content/img/illustrations/small-flower2.svg" width="138"/>'; 
 

 
console.dir(str.match(/"\/desktop\/content([^"]*)"/gm)); 
 
console.log(str.match(/"\/desktop\/content([^"]*)"/gm)[0]);

https://regex101.com/r/ahjdCZ/1

...あなたは本当にそれが<imgだことを確認したい場合は...あなたも可能性がタグ付け:

/(?!<img.*)"([^"]+)"/ 

または任意の< >内をタグ:

/<.*"(\/desktop\/content[^"]+)".*>/ 
関連する問題