我想知道用它中的vid_id替换这个字符串的最佳正则表达式
$code = '<object width="420" height="345"><br />
<param name="movie" value="http://www.badoobook.com/clips/swf/player.swf"></param><br />
<param name="allowFullScreen" value="true"></param><param name="flashvars" value="vid_id=100226&MainURL=http%3A%2F%2Fwww.bado obook.com%2Fclips&em=1"><br />
<embed src="http://www.badoobook.com/clips/swf/player.swf" flashvars="vid_id=100226&MainURL=http%3A%2F%2Fwww. badoobook.com%2Fclips&em=1" type="application/x-shockwave-flash" allowScriptAccess="always" width="420" height="345" allowFullScreen="true"></embed></object>'
$regular = '';
$code = preg_replace($regular ,'$1' , $code);
echo $code;
此代码中的vid ID为
值=
"
= VID_ID的 100226&
感谢您的帮助
答案 0 :(得分:2)
使用这个正则表达式:
vid_id=(\d+)
答案 1 :(得分:1)
您可以使用这样的正则表达式:
(?<=vid_id=)\d+
这使用positive lookbehind来匹配文字字符集“vid_id =”
之前的任意数字位数这里再次提到RegexBuddy评论:
@"
(?<= # Assert that the regex below can be matched, with the match ending at this position (positive lookbehind)
vid_id= # Match the characters “vid_id=” literally
)
\d # Match a single digit 0..9
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
"
您已使用php
和asp.net
标记了您的问题,因此我不确定您要执行的是哪种实施方式。以下是:
Asp.Net(C#)
Regex.Replace(@"...uot;vid_id=100226&...", @"(?<=vid_id=)\d+", "[Your value here]")
PHP
echo preg_replace("(?<=vid_id=)\d+", "[Your value here]", "...uot;vid_id=100226&...");