Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
/ post /:post_idパターンに一致するURLパスを評価したいと思います。
たとえば、/ post / 1、/ post / 2、/ post/mypostなどは一致する必要があります。
このためのreg式は何である必要がありますか?
URL の内容に応じて:post_id、数値の場合は次のように機能します。
:post_id
/^\/post\/\d+$/
基本的に、URL は で終わる必要があります/post/[0-9]+。値:post_idがあれば、次を使用できます。
/post/[0-9]+
/^\/post\/\w+$/
これは基本的に、URL が で終わる必要があることを示しています/post/[0-9A-Za-z_]+。受け入れたい他の文字は、追加できます。
/post/[0-9A-Za-z_]+
チェックするには、パターンの並べ替えから始めます ^ が使用されます。