Javascript字符串库 [英] Javascript String Library

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

问题描述

我正在使用Jquery进行DOM操作,并且发现它非常有价值.

I'm using Jquery for DOM manipulation, and I'm finding it invaluable.

有类似的字符串库吗?

我发现自己需要对部分字符串进行操作和运行选择器,我只是希望可以对其应用jquery语法.

I find myself needing to do manipulations and running selectors on parts of strings, and I just wish I can apply jquery syntax to it.

有人知道吗?

理想情况下,我会使用如下语法:

Ideally I would use a syntax like this:

var select = $(\regexmatch\)    
$(select:last:not(:last-child)).after("sometext").wrap("<wrapper></wrapper>");

如果答案是肯定的,那就没有问题了.

If the answer is, there is no such thing, that's fine too.

但是,没有人知道是否可以编写以这种方式在字符串上工作的自定义jquery选择器.

However, does anyone know if it's possible to write custom jquery selectors that would work on strings in this fashion.

推荐答案

您可以使用正则表达式对字符串进行强大的匹配和替换.它与JQuery选择器完全不同,因为它不基于CSS,但是功能更强大.

You can use regular expressions to do powerful matching and replacements in strings. It's completely different from JQuery selectors as it's not based on CSS, but it's more powerful.

例如,将span标签放在单词的所有出现处:

For example, put a span tag around all occurances of a word:

s = s.replace(/stackoverflow/g, '<span class="Found">$1</span>');

这篇关于Javascript字符串库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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