imb url by id bbcode

I want to get the link from src atribute by specific ID

For example I have following bbcode tags:

[img alt="" src="http://google.com" id="image"]
[img src="http://google.com" id="image2" alt=""]
[img id="image3" src="http://google.com" alt=""]

I tried with \[img(?:[^]]+src="(.+?)"[^]]+(?:id|class)="image"|[^]]+(?:id|class)="image"[^]]+src="(.+?)")

but for the second image it doesnt work

https://regex101.com/r/7owPlM/3

You could try something like this(https://regex101.com/r/SDYM7u/3):

\[img\s(?:.*?src="(.*?)".*?)?id="image"(?:.*?src="(.*?)".*?)?[^\]]*]

using flags g and m.The only downside is that in this case you will need to check both capture group 1 and 2 to find your url. When src precedes id attribute then the match is stored in Group 1 but when id attribute precedes src then the url is stored in group 2.