|
Posted by Chung Leong on 10/07/05 11:49
greatprovider wrote:
> i'm starting with a string such as "Na**3C**6H**5O**7*2H**20"
>
> im attempting to match all **\d+ ...once i can match all the double
> asterix \d i intend to wrap the \d in "<sub>" tags for display
> purposes.
>
> i have been trying to write the correct pattern for 2 weeks now without
> any success...i can get preg_replace() to work, with several simple
> patterns but when i use preg_match_all, i either get unintended results
> or incomplete matches.
>
> any assistance in matching all "\*{2}\d+" from the above string would
> be appreciated.
Why do you need preg_match_all for what you're trying to do?
preg_replace() should be adequate. If not that,
preg_replace_callback().
I am guessing here, but perhaps you're forgetting to capture the
digits?
echo preg_replace('/\*{2}(\d+)/', '<sub>\1</sub>',
"Na**3C**6H**5O**7*2H**20");
Appears to produce a correct representation of Sodium Citrate.
Navigation:
[Reply to this message]
|