使用jQuery在2个引号之间查找文本 [英] Find Text Between 2 Quotes with jQuery

查看:141
本文介绍了使用jQuery在2个引号之间查找文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我有这个小块文字:

ok, so I have this small block of text:

function onfocus(event) {
  if ($(this).val() == "Some Arbitrary Text") {$(this).val("");}
}

使用jQuery或JavaScript,我想找到任意文本。除任意文本外,此文本块是常量。理想情况下,我想要一种方法来解析它而不使用复杂的循环和正则表达式。

Using jQuery or JavaScript, I would like to find teh "Arbitrary Text". This text block is constant, with the exception of the "Arbitrary Text". Ideally, I would like a way to parse it without using complicated loops and regex.

为了帮助澄清:
文本是javascript的事实不起作用。把它想象成我正在解析的文本。 任意文本可以是任何东西,我试图在2个引号之间找到文本。

To help clarify: The fact that the text is javascript plays no part. Think of it as just text I am parsing. The "Arbitrary Text" can be anything, I am trying to find the text between the 2 quotes.

推荐答案

不是我理解完全问题,但也许

Not that I understood the question completely, but maybe

var s = 'foo "quoted" bar';
var m = s.match(/"(.*?)"/);
alert(m[1]); // m[1] = quoted

当然,没有正则表达式也可以这样做,但它会没有意义 - 这就是正则表达式

Of course, this is also possible without regexps, but it would make no sense - this is what regexps are for

这篇关于使用jQuery在2个引号之间查找文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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