Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6189303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:23:47+00:00 2026-05-24T02:23:47+00:00

I am currently working on some syntax highlighting in Javascript. To match strings, I

  • 0

I am currently working on some syntax highlighting in Javascript.

To match strings, I would use something like this:
code = code.replace(/("([^"\\]*(\\.[^"\\]*)*)")/gm, "<span class=\"string\">$1</span>"); // string

This would match an integer:
code = code.replace(/(\d+)/gm, "<span class=\"number\">$1</span>");

Now my problem is that an integer within a string would get matched too. It’s not a problem of highlighting but of performance, since I could use
code > span.number instead of code span.number.
Any suggestions for preventing this kind of behavior?


I also read through TextMate’s Language Grammars which seem really powerful to me. However, I have no idea how I could implement that in Javascript.
Some help would really be appreciated.


I know that there are many good syntax highlighting things around, but none of them provides really good support for Objective-C.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:23:48+00:00Added an answer on May 24, 2026 at 2:23 am

    If you want to write an objective-C mode for Google Code Prettify I would be happy to incorporate it.

    You can see an example mode for OCAML/SML style languages at http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-ml.js

    Lines like

    [PR['PR_STRING'],
     /^(?:\"(?:[^\"\\]|\\[\s\S])*(?:\"|$)|\'(?:[^\'\\]|\\[\s\S])(?:\'|$))/, null, '"\'']
    

    say that this is a highlighting rule for a string and a string matches the regular expression above (a run of non-quotes or escape sequences inside double quotes or a run of non-single-quotes or escape sequences inside single quotes).

    This rule

    [PR['PR_LITERAL'],
     /^[+\-]?(?:0x[\da-f]+|(?:(?:\.\d+|\d+(?:\.\d*)?)(?:e[+\-]?\d+)?))/i],
    

    matches number literals. A number literal is an optional sign followed by one of a hex literal, a dot followed by a fraction, or an integer part followed by a fraction, and the last two can have an optional exponent at the end.

    The code prettify engine takes care of making sure that strings are treated as strings and things that look like numbers inside strings are not mistaken for numbers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working with some developers who like to set up Ant tasks that
I am currently working on some Ajax heavy code and I am wondering how
I am working on some SEO for my site, and using urls like category/this-cat.html
I am currently working with some of my teacher's old Postgres SQL code and
I'm currently working on some evaluation work for a project that I'm planning. I
I am currently working with some users that do not have the .NET Framework
I'm currently working through some exercises in a c++ book, which uses text based
I am currently working on some simple custom allocators in c++ which generally works
I'm currently working on databinding some of my existing Windows Forms, and I've ran
The system I am currently working on requires some role-based security, which is well

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.