正则表达式,这些字符串应该是什么样的短代码?

时间:2017-06-28 05:36:31

标签: php regex

示例短代码是

[su_slider source="media: 11862,11864,11866,11863,11865,11861,11867" width="340" height="220" pages="no" autoplay="0"]

我想得到11862,11864,11866,11863,11865,11861,11867与常规模式和PHP的短代码

模式应该是什么?

2 个答案:

答案 0 :(得分:1)

$subject = '[su_slider source="media:11862,11864,11866,11863,11865,11861,11867" width="340" height="220" pages="no" autoplay="0"]';

$pattern = '/source="media:[\s]?([0-9,]+)\"/';

preg_match($pattern, $subject, $match);

var_dump($match);

如果匹配,则$match[1]就是您想要的。

答案 1 :(得分:0)

试试这个:

<?php

$shortcode = '[su_slider source="media: 11862,11864,11866,11863,11865,11861,11867" width="340" height="220" pages="no" autoplay="0"]';

preg_match('~ source="media: \K[^"]+~', $shortcode, $match);

var_dump($match[0]);

输出:

string(41) "11862,11864,11866,11863,11865,11861,11867"

直播DEMO