正则表达式来修改的htmlText AS3网址 [英] RegEx to modify urls in htmlText as3

查看:125
本文介绍了正则表达式来修改的htmlText AS3网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我设置成闪烁一个TextField一些HTML文本。我要强调的链接(或者在一个不同的颜色,可以仅通过使用下划线和确保链接目的地被设定为_blank

I have some html text that I set into a TextField in flash. I want to highlight links ( either in a different colour, either just by using underline and make sure the link target is set to "_blank".

我真的不擅长的正则表达式。我发现了一个方便的EX $ P $在 RegExr pssion:

I am really bad at RegEx. I found a handy expression on RegExr :

 </?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)/?>

但我不能使用它。

but I couldn't use it.

我将处理是这样的:

<a href="http://randomwebsite.web" />

我需要做一个与string.replace()

I will need to do a String.replace()

要得到这样的:

<u><a href="http://randomwebsite.web" target="_blank"/></u>

我不知道这会在一气呵成完成。重点是确保在链路目标设置为空白。

I'm not sure this can be done in one go. Priority is making sure the link has target set to blank.

推荐答案

我建议你这个简单的测试工具 HTTP://www.regular-ex$p$pssions.info/javascriptexample.html

I recomend you this simple test tool http://www.regular-expressions.info/javascriptexample.html

下面是一个工作示例更复杂的输入字符串。

Here's a working example with a more complex input string.

var pattern:RegExp = /<a href="([\w:\/.-_]*)"[ ]* \/>/gi;
var str:String = 'hello world <a href="http://www.stackoverflow.com/" /> hello there';
var newstr = str.replace(pattern, '<li><a href="$1" target="blank" /></li>');
trace(newstr);

这篇关于正则表达式来修改的htmlText AS3网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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