|
Posted by Alan Little on 11/27/95 11:49
Carved in mystic runes upon the very living rock, the last words of
greatprovider of comp.lang.php make plain:
> Alan Little wrote:
>> Carved in mystic runes upon the very living rock, the last words of
>> greatprovider of comp.lang.php make plain:
>>
>> > 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.
>>
>> The expression you have works fine for me. You'll have to give more
>> information about what's happening. "It doesn't work" isn't much to
>> go on.
>
> unformated: Ca(C**2H**3O**2)**2
>
> formated: Ca(C<sub>2</sub>H**3O<sub>2</sub>)<sub>2</sub>
>
> using: preg_match_all('/\*{2}[\d]+/', $formula, $my_arr)
>
> any combination of patterns i try, this is as close as i can get.
What is? What's as close as you can get? You still haven't said what
you're getting. And what are you trying to get? What you have for
"formatted", there is no way you're going to get that with
preg_match_all, just by itself. preg_replace might do it for you, but you
said that you have that working. So what exactly are you trying to do
with preg_match_all?
http://www.catb.org/~esr/faqs/smart-questions.html
I just ran your example above, and I get:
Array
(
[0] => Array
(
[0] => **2
[1] => **3
[2] => **2
[3] => **2
)
)
--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
[Back to original message]
|