Javascript

Javascript/正規表現

REST API で使いそうなサンプル

パス解析

// パスの形式 : sample/{groupId}(/{userId})
const pathDifinition = /^sample\/(?<groupId>[a-zA-Z0-9-_]+)(\/(?<userId>[a-zA-Z0-9-_]+)){0,1}$/

// 解析
// event.pathParameters.proxy (例: sample/group-012/user-545)
const pathParams = event.pathParameters.proxy.match(pathDifinition).groups;

console.log(pathParams.groupId);    // group-0912
console.log(pathParams.userId);     // user-545

その他パラメータ

トップ   差分 バックアップ リロード   一覧 検索 最終更新   ヘルプ   最終更新のRSS