试图构建正则表达式需要输入

时间:2014-04-20 12:31:35

标签: regex

我有一个字符串

<sip:a39pbx@47.168.156.141:5060;maddr=47.168.156.141>;expires=703,<sip:739pbxast25@47.168.156.141:5060;maddr=47.168.156.141>;expires=826;

想要提取过期及其值,我尝试过使用

(.*)(expires=\d*);(.*)

但是它只给了我expires=826的最后一个,我想选择其他或者以,结尾。

赞赏任何意见。

2 个答案:

答案 0 :(得分:0)

您应该尝试:

(expires=(\d+)),

最后一个逗号将帮助您匹配以,结尾的值。它将给出两个匹配一个与键和&amp;价值和另一个只有价值。

Live Demo

答案 1 :(得分:0)

(expires=\d+)

http://regex101.com/r/sQ5bJ7

(expires=\d+)

Match the regular expression below and capture its match into backreference number 1 «(expires=\d+)»
   Match the characters “expires=” literally «expires=»
   Match a single digit 0..9 «\d+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»