开发者

"or" in regex, how to find one value or the other

How would you search for one value or another using regex:

For example:

[video= SOMETHING NOT IMPORTANT]
[image= SOMETHING NOT IMPORTANT]

So either look for video or image:

/\[video|image=(开发者_运维百科[^\]]+)\]/i

How would this be done?


I believe you'll need to wrap video|image in its own subpattern:

/\[(?:video|image)=([^\]]+)\]/i

The ?: designates it a non-capture group so your capture/backreference to ([^\]]+) is untouched.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜