正規表現を使用して文字列一致の問題を解決しようとしています。次の形式の URL を照合する必要があります。
http://soundcloud.com/okapi23/dont-turn-your-back/
そして、このフォームの URL を「拒否」する必要があります。
http://soundcloud.com/okapi23/sets/happily-reversed/
末尾の「/」は明らかにオプションです。
だから基本的に:
- ホスト名の後に 2 つまたは 3 つのグループがあり、2 番目のグループが"sets"と等しい場合 、正規表現は一致しません。
- 「sets」は URL のどこにでも含めることができます
- 「セット」は完全に一致する必要があります
私がこれまでに思いついたのはhttp(s)?://(www\.)?soundcloud\.com/.+/(?!sets)\b(/.+)?
、失敗することです。
助言がありますか?タスクを簡素化するライブラリはありますか (たとえば、末尾のスラッシュをオプションにするなど)?