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

  • SEARCH
  • Home
  • 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 8990185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:26:44+00:00 2026-06-15T22:26:44+00:00

The title might seem a bit recursive, and indeed it is. I am working

  • 0

The title might seem a bit recursive, and indeed it is.

I am working on a Javascript which can highlight/color Javascript code displayed in HTML. Thus, in the Internet Browser, comments will be turned green, definitions (for, if, while, etc.) will be turned a dark blue and italic, numbers will be red, and so on for other elements. However, the coloring is not all that important.

I am trying to figure out two different regular expressions which have started to cause a minor headache.

1. Finding a regular expression using a regular expression

I want to find regular expressions within the script-tags of HTML using a Javascript, such as:

    match(/findthis/i);

, where the regex part of course is “/findthis/i“.

The rules are as follows:

  1. Finding multiple occurrences (/g) is not important.
  2. It must be on the same line (not /m).
  3. Caseinsensitive (/i).
  4. If a backward slash (ignore character) is followed directly by a forward slash, “/”, the forward slash is part of the expression – not an escape character. E.g.: /itdoesntstop\/untilnow:/
  5. Two forward slashes right next to each other (//) is: (A) At the beginning: Not a regex; it’s a comment. (B) Later on: First slash is the end of the regex and the second slash is nothing but a character.
  6. Regex continues until the line breaks or end of input (\n|$), or the escape character (second forward slash which complies with rule 4) is encountered. However, also as long as only alphabetic characters are encountered, following the second forward slash, they are considered part of the regex. E.g.: /aregex/allthisispartoftheregex

So far what I’ve got is this:

    '\\/(?:[^\\/\\\\]|\\/\\*)*\\/([a-zA-Z]*)?'

However, it isn’t consistent. Any suggestions?

2. Find digits (alphanumeric, floating) using a regular expression

Finding digits on their own is simple. However, finding floating numbers (with multiple periods) and letters including underscore is more of a challenge.

All of the below are considered numbers (a new number starts after each space):

3 3.1 3.1.4 3a 3.A 3.a1 3_.1

The rules:

  1. Finding multiple occurrences (/g) is not important.
  2. It must be on the same line (not /m).
  3. Caseinsensitive (/i).
  4. A number must begin with a digit. However, the number can be preceeded or followed by a non-word (\W) character. E.g.: “=9.9;” where “9.9” is the actual number. “a9” is not a number. A period before the number, “.9“, is not considered part of the number and thus the actual number is “9”.
  5. Allowed characters: [a-zA-Z0-9_.]

What I’ve got:

'(^|\\W)\\d([a-zA-Z0-9_.]*?)(?=([^a-zA-Z0-9_.]|$))'

It doesn’t work quite the way I want it.

  • 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-06-15T22:26:45+00:00Added an answer on June 15, 2026 at 10:26 pm

    For the first part, I think you are quite close. Here is what I would use (as a regex literal, to avoid all the double escapes):

    /\/(?:[^\/\\\n\r]|\\.)+\/([a-z]*)/i
    

    I don’t know what you intended with your second alternative after the character class. But here the second alternative is used to consume backslashes and anything that follows them. The last part is important, so that you can recognize the regex ending in something like this: /backslash\\/. And the ? at the end of your regex was redundant. Otherwise this should be fine.

    Test it here.

    Your second regex is just fine for your specification. There are a few redundant elements though. The main thing you might want to do is capture everything but the possible first character:

    /(?:^|\W)(\d[\w.]*)/i
    

    Now the actual number (without the first character) will be in capturing group 1. Note that I removed the ungreediness and the lookahead, because greediness alone does exactly the same.

    Test it here.

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

Sidebar

Related Questions

the title might be a little bit confusing, let me explain, ;) I have
I asked a question , title of which might have been misleading so I'm
The title might be a bit misleading, but I don't know how else to
This might seem a bit awkward but I want to start a console program
I know that the title might seem silly, couldn't think of something better, sorry.
This might seem like a duplicate question, but I can't find any information on
I have this HTML code: <HTML> <HEAD> <TITLE></TITLE> </HEAD> <BODY> <form action=http://www.aweber.com/scripts/addlead.pl method=post> <input
The title may seem slightly self-contradictory, and I accept that you can't really learn
From reading the title it might seem like an odd request, so let me
The title might seem unsettling, but let me explain. I'm facing an interesting challenge,

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.