1

私はこのようなウェブサイト構造を持っています:

/docs/one_of_the_resources/one-of-the-resources.html
/docs/a_complete_different_resource/a-complete-different-resource.html

URL内のすべてのサブフォルダーを取り除き、これを取得したい:

/one-of-the-resources.html
/a-complete-different-resource.html

サブフォルダーは影響を受けません。

/docs/one_of_the_resources/assets/*

フォルダー名は常に html ファイルと同じですが、ダッシュが下線に置き換えられ、もちろん接尾辞はありません。

私はgrunt-contrib-rewriteと grunt-connect を使用しています。

私の頭を包むことはできません。これは可能ですか?

4

1 に答える 1

2

否定文字クラスを使用できます

/\/[^/]+$/
  • [^/]+以外のものに一致し/ます。数量詞+は、1 つ以上の文字を保証します。

  • $文字列の末尾に正規表現を固定します。

正規表現のデモ

string = "/docs/one_of_the_resources/one-of-the-resources.html";
console.log(string.match(/\/[^/]+$/)[0]);
// => one-of-the-resources.html
于 2015-06-26T11:18:11.407 に答える