Regex 可选url参数的正则表达式规则
如何为特定的给定url参数编写regrex规则 对于exmaple,我有以下URL:Regex 可选url参数的正则表达式规则,regex,Regex,如何为特定的给定url参数编写regrex规则 对于exmaple,我有以下URL: http://localhost:5008/api/products/productsSubscribeStatus?companyId=14 http://localhost:5008/api/products/productsSubscribeStatus http://localhost:5008/api/products/productsSubscribeStatus?ccc=14 我希望规则只与“pr
http://localhost:5008/api/products/productsSubscribeStatus?companyId=14
http://localhost:5008/api/products/productsSubscribeStatus
http://localhost:5008/api/products/productsSubscribeStatus?ccc=14
我编写regrex:
\/products\/productsSubscribeStatus(\?companyId=\d+$)?
,但它不能保证参数仅为companyId
。我只会将整个预期查询参数设置为可选:
^https?://.+/products/productsSubscribeStatus(?:\?companyId=\w+)?$
也不接受任何查询参数吗?是的,在我的示例中,我希望url 1和2传递,但不希望传递第三个。仅允许url不带参数或仅带
companyId
的参数。