Q:

How change regular expression on http/https?

I use a regular expression to get all SRC paths in HTML code.
'/src="http?:\/\/[^"]*\.(jpg|jpeg|png)"/i'

How I can add https to expression?
I tried:
 '/src="http|https?:\/\/[^"]*\.(jpg|jpeg|png)"/i'

A:

Just add s next to p in http and make it as optional by adding the quantfier ? next to the s
'/src="https?:\/\/[^"]*\.(jpg|jpeg|png)"/i'

http? in your regex makes p as optional. Don't do that.
If you want to make the whole http:// or https:// as optional, you need to put them inside a capturing or non-capturing group and then make it as optional by adding the quantifier ? next to that added group.
'/src="(?:https?:\/\/)?[^"]*\.(jpg|jpeg|png)"/i'

