The Question
Is it possible to make a subpattern non-obligatory in the same way that you that you can make alpha-numeric characters (ex: "https?" matches both "http" and "https" non-obligatory?
The Reason
The reason I ask is because I'm trying to match a BB-Code tag with an optional-attribute. What I'm trying to match is [img=<URL>( align=<left|center|right>)] where the " align=..." is non-obligatory.
Currently I am using:
'/(\[img=(.*?)\])|(\[img=(.*?) align=(left|center|right))\]/i'
This patterns works perfectly, but in search of something (potentially) more efficient... I am trying to utilize optional-subpatterns:
Attempt 1:
'/(\[img=(.*?)(?:(\s(align=(left|center|right))))\]/i'
Attempt 2:
'/(\[img=(.*?)(\s(align=(left|center|right)))?\]/i'
So is what I'm attempting to do completely oblivious of me? I did check the PHP-Manual for some help and I came across Conditional-Subpatterns, but I Non-Obligatory Subpatterns seemed to be the way to go.