匹配带有可选字符的字符串

Match string with optional char

我想从下面的 URL 中捕获 'com.ouest.france' 我已经尝试使用此正则表达式来做到这一点

play.google.com\/store\/apps\/details\?id=(.*)[?&]

看这里http://www.rubular.com/r/NMxRo4grSL

https://play.google.com/store/apps/details?id=com.ouest.france&hl=de https://play.google.com/store/apps/details?id=com.ouest.france

但是,如果没有 & 符号,它就不起作用。

有什么想法吗?

最好告诉小组匹配除&

以外的所有内容
play.google.com\/store\/apps\/details\?id=([^&]*)

http://www.rubular.com/r/JA0rjpQcG9

问题是您的正则表达式期望末尾有 ?&。使其成为可选的

play.google.com\/store\/apps\/details\?id=(.*?)([?&]|$)

允许?&行尾。

此致