Regex 可选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

如何为特定的给定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
  • 我希望规则只与“products/productsSubscribeStatus”匹配,并且只与参数“companyID=xx”匹配,但不与其他参数(如第三个)一起传递url


    我编写regrex:
    \/products\/productsSubscribeStatus(\?companyId=\d+$)?
    ,但它不能保证参数仅为
    companyId

    我只会将整个预期查询参数设置为可选:

    ^https?://.+/products/productsSubscribeStatus(?:\?companyId=\w+)?$
    

    也不接受任何查询参数吗?是的,在我的示例中,我希望url 1和2传递,但不希望传递第三个。仅允许url不带参数或仅带
    companyId
    的参数。