如何从较大的字符串中提取字符串? [英] How to extract a string from a larger string?

查看:112
本文介绍了如何从较大的字符串中提取字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果输出的HTML页面有以下内容,使用jQuery如何找到/提取Spartan字符串..

Using jQuery how would I find/extract the "Spartan" string if the outputted HTML page had the following..

<a href="/mytlnet/logout.php?t=e22df53bf4b5fc0a087ce48897e65ec0">
  <b>Logout</b>
</a> : Spartan<br>


推荐答案

正则表达式。或者通过以更繁琐的方式拆分字符串

由于我不是一个大的正则表达式瘾君子,我可能会使用.text()获得文本等效,然后将结果拆分为:,并获取第二个索引(这将是是'斯巴达'文本。)

Since I'm not a big regex-junkie, I would likely get the text-equivalent using .text(), then split the result on ":", and grab the second index (which would be the 'Spartan' text).

这篇关于如何从较大的字符串中提取字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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