0

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?

2
  • 4
    where's the opening slash (/)? Commented Apr 22, 2012 at 0:38
  • @Joseph I'll admit, today is my first work with RegEx. Thanks for pointing that out though, I'll make sure I go and add that now. +1 for you! Commented Apr 22, 2012 at 0:57

1 Answer 1

1

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>'));
Sign up to request clarification or add additional context in comments.

2 Comments

Wow, nice catch. I figured it must be something obscure like that! I'll Have to make sure I keep that in mind for next time...
@DadeLamkins - You and me both! I only noticed it because it showed up like that in an alert box while I was playing with your regex. In the HTML it obviously just shows up as >>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.