[Greasemonkey] Using Regular Expressions

Nikolas Coukouma lists at atrus.org
Sat May 28 20:20:43 EDT 2005

John Horner wrote:

> Am I right in thinking that GreaseMonkey alone can't reformat a page
> using regular expressions?
> I've achieved my desired result using Platypus, but of course for
> third parties it would be better if they needed to install just
> GreaseMonkey. 

It certainly can. The HTML is just a string in Javascript. The language
has full regex support and a nice string object.

Assuming el is an element in the page (document.body, something from
XPath or getElementByID or whatever):
el.innerHTML = el.innerHTML.replace(  /([A-Z])[a-z]/g, 'y$1z' );

Nice overview of strings in JS: http://mozref.com/reference/objects/String
Dive Into Greasemonkey section:

-Nikolas Coukouma

More information about the Greasemonkey mailing list