如何使用正则表达式提取查询字符串值?

时间:2015-07-29 14:36:07

标签: regex

我的字符串是:

/excursion/popupPortPOI.do?voyageCode=S515&tourCode=&travelOrder=A&portid=SYD
/excursion/popupPortPOI.do?voyageCode=S515&tourCode=&travelOrder=A&portid=BNE
/excursion/popupPortPOI.do?voyageCode=D520&tourCode=&travelOrder=A&portid=JFM
/excursion/popupPortPOI.do?voyageCode=D520&tourCode=&travelOrder=A&portid=SYD
/excursion/popupPortPOI.do?voyageCode=S517&tourCode=&travelOrder=A&portid=BNE

我对使用正则表达式提取航次代码感兴趣。在这种情况下,我会寻找它返回以下值:

S515

S515

D520

D520

S517

1 个答案:

答案 0 :(得分:2)

也许这个:

((?<=voyageCode=)[^=&\s]+)|((?<=portid=)[^=&\s]+)

Regex live here.