开发者

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

开发者 https://www.devze.com 2023-03-03 03:37 出处:网络
How would you search for one value or another using regex: For example: [video= SOMETHING NOT IMPORTANT]

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

精彩评论

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