I got my original regular expression to work, and I figured I could get this one working because it’s very similar; however, I cannot.
This code is being used for a template system where links are replaced by javascript or HTML depending on whether JS is enabled on the user’s browser.
An example string would look like this:
help{:footerlink}{::helpFooter}
“help” would be the text displayed in the link itself.
“footerLink” is the CSS class that should be applied to the link
“helpFooter” is the CSS id that should be applied to the link
Here is the code I am trying to use:
$string = 'help{:footerlink}{::helpFooter}';
$classIDExp = '/([a-z0-9]+)\{:([a-z0-9]+)\}\{::([a-z0-9]+)\}/i';
$display = preg_replace($idexp, "$1", $string);
$class = preg_replace($idexp, "$2", $string);
$cssID = preg_replace($idexp, "$3", $string);
$curLink = 'Display Text: ' . $display . '<br />' .
'Class: ' . $class . '<br />CSS ID: ' . $cssID;
echo $curLink;
This code outputs:
Display Text: help{:footerlink}{::helpFooter}
Class: help{:footerlink}{::helpFooter}
CSS ID: help{:footerlink}{::helpFooter}
The proper output would be:
Display Text: help
Class: footerlink
CSS ID: helpFooter
The link ID is retrieved just fine, but the display text, css class, and css ID can’t be found. I tried escaping the colons (:) as well, but it still shows the same output.
Any help is greatly appreciated, because as I said before, I am far from an expert on regular expressions. 🙁
1 Answer