Freesnöw
Freesnöw

Reputation: 32143

I can't get my RegEx expression to work in JavaScript

I'm using the following on my site:

$('body').html($('body').html().replace(>> ?(\d+)/g, '<b>$&</b>'));

(I'm using jQuery)

The Regular Expression I'm using is >> ?(\d+)/g. The Bold below shows what it should be replacing:

This passage of text >> 124949200 contains two slightly >>20993910 different regular expressions.

Now, I've used this tool here: http://regexpal.com/ and my RegEx works fine. When I actually implement it, however, it doesn't work.

Any ideas?

Upvotes: 0

Views: 83

Answers (1)

Karl Nicoll
Karl Nicoll

Reputation: 16419

JQuery's html() function appears to be outputting the >> as encoded characters: &gt;&gt;. Simply change your regular expression to this:

$('body').html($('body').html().replace(/&gt;&gt; ?(\d+)/g, '<b>$&</b>'));

Upvotes: 1

Related Questions