2011-12-19 102 views
0

对于一个项目,我试图将htmlText导入到闪存中,然后删除闪存不会处理的任何项目。例如,我想要导入的html包含自定义的“[caption] [/ caption]”代码。我基本上想要删除这些标识符和它们之间的任何文本,这样Flash就不会在文本字段中显示它们。有没有人对我有好的建议/例子?我一直在试图弄清楚如何使用正则表达式来做到这一点,但一直没有找到一个好的指导,因此失败了。从AS3中的html字符串中删除某些标识符中的文本

与示例文本的,我想筛选:

<em>Pushmo</em> is a game filled with questions. How do I solve this puzzle? Is that a 8-bit Mario's face? Why is this old, obese blob making tons of death traps that easily ensnare and encase unsuspecting children? 

[caption id="attachment_37414" align="alignleft" width="400" caption="The fat, red sumo goes into the most dangous place imaginable."]<a href="/2011/12/pushmo-review/pushmo-3ds-title-screen/" rel="attachment wp-att-37414"><img class="size-medium wp-image-37414" title="Pushmo-title" src="/2011/12/pushmo-3ds-title-screen-400x203.jpg" alt="Pushmo Title Screen" width="400" height="203" /></a>[/caption] 

<em>Pushmo</em> is a downloadable puzzle game in the 3DS eShop. In <em>Pushmo</em> you take on the role of Mallo, an amorphic red sumo wrestler with the mind of an Einstienian savant. 

我期待能够检测识别文本并删除它们之间的任何东西。我会很感激任何人都可以给我的建议。

回答

1

你也许可以使用indexOflastIndexOf来实现这一点,而无需使用正则表达式。

你也应该看看String.replace

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/String.html

和AS3正则表达式教程:

http://snipplr.com/view/6608/as3-regular-expression-basics/

终于为纯正则表达式的教程:

http://www.regular-expressions.info/tutorial.html

+0

我想使用字符串替换,但标识符之间的值不会相同。我可以使用索引并以某种方式运行循环。 Reg表达式看起来应该是有意义的,但我还没有能够得到一个自定义的表达式,所以我认为如果我要这样做的话,这需要更多的研究。每次我尝试一个正则表达式时,都找不到合适的术语。我不认为我理解它的关键。 – Ghost9 2011-12-19 03:00:53

+0

正则表达式在开始时很难理解,但如果坚持下来,您可以开始理解它。我自己并不擅长,但我知道如果你得到'[caption]'和'[/ caption]'的索引并获得这些索引的子字符串,你可以删除 – annonymously 2011-12-19 03:03:35

+0

之间的内容。真棒,我只是试过并让它工作!我现在需要做的就是把它放在循环中,直到索引达到-1,以便它将删除所有实例。谢啦! (或女人) – Ghost9 2011-12-19 03:10:37