找不到preg_match_all的正确PCRE模式 [英] can't find the right PCRE pattern for a preg_match_all

查看:69
本文介绍了找不到preg_match_all的正确PCRE模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个字符串开始,例如Na ** 3C ** 6H ** 5O ** 7 * 2H ** 20


我试图匹配所有** \d + ...一旦我能匹配所有的双重

asterix \ di打算将\d包装在<< sub>"用于显示的标签

用途。


i一直试图写出正确的模式2周,而不是

任何成功.. .i可以使用几个简单的

模式来运行preg_replace(),但是当我使用preg_match_all时,我会得到意想不到的结果

或不完整的匹配。


匹配所有\ * {2} \d +的任何帮助从上面的字符串中得到赞赏。

解决方案

在活石上刻上神秘的符文,

comp.lang.php的伟大提供者的最后一句话简单说明:

我从一个字符串开始,例如Na ** 3C ** 6H ** 5O ** 7 * 2H ** 20

我试图匹配所有** \d + ...一旦我能匹配所有的双星号\\ / asterix \\ \\ di打算将\d包装在<< sub>"标签用于显示
目的。

我一直在努力编写正确的模式2周,而没有任何成功...我可以让preg_replace()工作,几个简单的模式,但是当我使用preg_match_all时,我会得到意想不到的结果
或不完整的匹配。




你的表达对我来说很好。你将不得不提供更多

的信息,了解发生了什么。 它不起作用是不是很高兴

on。


-

Alan Little

Phorm PHP表单处理器
http://www.phorm.com/


unformated:Ca(C ** 2H ** 3O ** 2)** 2


格式:Ca(C< sub> ; 2< / sub> H ** 3O< sub> 2< / sub>)< sub> 2< / sub>


使用:preg_match_all(''/ \ * {2} [\d] + / '',

式中,

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.

解决方案

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.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/


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,


这篇关于找不到preg_match_all的正确PCRE模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆