"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.
精彩评论