0

I have made my self a custom javascript syntax highlighter

<p id="data">// return
function getdata() {
    // return hi
     return "Hi";
}</p>
data = $('p#data').html();
data = data.replace(/\/\/.*$/gm, "<font color=#878A85>$&</font>");
data = data.replace(new RegExp(getRegx('return'), 'gmi'), "<font color=#C97F00>$&</font>");
$('p#data').html(data);

Now, what my problem is that it will replace the return keyword in the comments also is there a way to avoid this and how do i number each line i don't want to use any pre built script because i am only going to use php script i don't want more stuff.

1
  • 4
    FYI: font-tags are deprecated since html 4. I suggest using a span Commented Aug 18, 2012 at 16:56

1 Answer 1

1

Try to use negative lookahead /return(?!.*<\/font>)$/

<p id="data">
    // return
    function getdata() {
       // return hi
       return "Hi";
    }
</p>
data = $('p#data').html();
data = data.replace(/\/\/.*$/gm, "<font color=#878A85>$&</font>");
data = data.replace(new RegExp(getRegx('return(?!.*<\/font>$)'), 'gmi'), "<font color=#C97F00>$&</font>");
$('p#data').html(data);
Sign up to request clarification or add additional context in comments.

Comments

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.