How to convert a specific word followed by digits to subscript in a string using PHP?
$nutrients = "Vitamin A, Vitamin B1, Vitamin B12, 1-Octamine, 1,2,Hydroxyethyl";
Vitamin A, Vitamin B<sub>1</sub>, Vitamin B<sub>12</sub>, 1-Octamine, 1,2,Hydroxyethyl
This should subscript any number after
$nutrients = preg_replace('~(Vitamin [A-Z])(\d+)~', '$1<sub>$2</sub>', $nutrients);
The character class might not be needed, is vitamin B the only one that can have subscripts?
+ quantifier requires the preceding character be present, the
* does not.