开发者

Find text in a string and prependTo somewhere else

I am trying to find some text RegEx /\w*http:[/][/]bit.ly[/]\w*/ig that will f开发者_Go百科ind this string and pull it out, moving it to the <span> tag, or at the end of the <p> tag?

<p class="regex">Text before http://bit.ly/wtGAhsu sometext here, doesn't matter how long this is.... <span></span></p>

$("p:regex('(\w*http:[/][/]bit.ly[/]\w*)')").addClass('active');

Above is what I have so far (just selecting the p), I've tried .highlight() but Im not sure now to grab the text and move it, any help is much appreciated.

Thanks


You could use something like this:

$("p.regex").each ( function () {
    var jThis   = $(this);
    var newSrc  = jThis.text ().replace (/^(.*)(https?\:\/\/bit\.ly\/\w+)(.*)$/i, '$1$3<span>$2</span>');
    jThis.html (newSrc);
} );

Note that this version assumes one link, max, per paragraph.

See it in action at jsFiddle.


Try the following:

HTML:

<div id="moveToArea"></div>

Javascript:

$("p:regex('(\w*http:[/][/]bit.ly[/]\w*)')").addClass('active');
var item = $(".active")
$("$moveToArea").append(item, function(){
item.fadeOut();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜