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?
Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.
Save this question. . means match any character in regular expressions. * means zero or more occurrences of the SINGLE regex preceding it. My alphabet.txt contains a line abcdefghijklmnopqrstuvwxyz.
Alternation is the term in regular expression that is actually a simple “OR”. In a regular expression it is denoted with a vertical line character | . For instance, we need to find programming languages: HTML, PHP, Java or JavaScript.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With