views:

122

answers:

1

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

Is there a similar library for strings?

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.

Anyone know of anything like that?

Ideally I would use a syntax like this:

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

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

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

+1  A: 

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.

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

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