473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Javascript RegEx problem

I am working on modifying a syntax highlighter written in
javascript and it uses several regexes. I need to add a
language to the avail highlighters and need the following regexes
modified to parse the new language, Delphi/Pascal. Source to the
highlighter is avail here:
http://www.dreamprojections.com/Synt...r/Default.aspx
**********************************************
COMMENTS
**********************************************
regex = new RegExp('//.*$|/\\*[^\\*]*(.)*?\\*/', 'gm');
Matches- single line comment: '// ' until end of line
multi line comment '{' until closing '}'
Example:

// This is a Comment

{
This is
a multiline comment
}

**********************************************
STRINGS
**********************************************
regex = new RegExp('"(?:\\.|[^\\""])*"', 'g');
Matches - any text enclosed in single quotes
if the string contains single quotes it will be
escaped like this:
'isn''t that grand'
Example:

'this is a string'

**********************************************
DIRECTIVES/REGIONS
**********************************************
regex = new RegExp('^\\s*{/$.*', 'gm');
Matches - '{' followed by '$' followed by 1+ Alpha chars
closed with '}'
Example:

{$IFDEF YAHOO} // this is a directive
{$ELSE YAHOO} // this is a directive
{$ENDDEF YAHOO} // this is a directive

{$R *.res} // this is a directive

**********************************************
NUMBERS
**********************************************
regex = new RegExp('/[^\d]/gi', 'g');
Matches - integer = numeric chars only
float = numerics and decimal only, no commas
hex = '$' foloewd by any combination of 'A'-'F'
and/or 0-9
Example:

x := x + 1234; // example of a number
y := y + 1.0; // example of a float number
z := $FFAA; // example of a hex number
for instance, in the first example:
regex = new RegExp('//.*$|/\\*[^\\*]*(.)*?\\*/', 'gm');
Matches - single line comment: '// ' until end of line
multi line comment '{' until closing '}'
Example:

// This is a Comment

{
This is
a multiline comment
}
the line:
regex = new RegExp('//.*$|/\\*[^\\*]*(.)*?\\*/', 'gm');

is the current regex.

the line(s):
- single line comment: '// ' until end of line
multi line comment '{' until closing '}'

spell out what I want the regex to match

and this:
Example:

// This is a Comment

{
This is
a multiline comment
}
Here is another one that I can't figure out.

Source:
asm
MOV AX,1234H
MOV Number,AX
end;

Need to match everything between the 'asm' and 'end;'
Jul 23 '05 #1
2 1842
JRS: In article <1107269716.711be950c458361567b8868ee0225138@teran ews>,
dated Tue, 1 Feb 2005 08:55:14, seen in news:comp.lang.javascript, Mr.
Clean <mrclean@p&g.com> posted :
I am working on modifying a syntax highlighter written in
javascript and it uses several regexes. I need to add a
language to the avail highlighters and need the following regexes
modified to parse the new language, Delphi/Pascal. Source to the
highlighter is avail here:
http://www.dreamprojections.com/Synt...r/Default.aspx
**********************************************
COMMENTS
**********************************************
regex = new RegExp('//.*$|/\\*[^\\*]*(.)*?\\*/', 'gm');
Matches- single line comment: '// ' until end of line
multi line comment '{' until closing '}'
Needs also to support comment (* ... *).
One type of comment can contain the opening symbol for another.

**********************************************
DIRECTIVES/REGIONS
**********************************************
regex = new RegExp('^\\s*{/$.*', 'gm');
Matches - '{' followed by '$' followed by 1+ Alpha chars
closed with '}'
Also (*$ ... *)

**********************************************
NUMBERS
**********************************************
regex = new RegExp('/[^\d]/gi', 'g');
Matches - integer = numeric chars only
float = numerics and decimal only, no commas
hex = '$' foloewd by any combination of 'A'-'F'
and/or 0-9


Also needs to handle such as 3.5e4 6.99E-07 .

Note that, to aid Continentals, (. and .) can be used for [ and ] -
there may be others similar that I have forgotten.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
Jul 23 '05 #2
<SNIP>
Also needs to handle such as 3.5e4 6.99E-07 .

Note that, to aid Continentals, (. and .) can be used for [ and ] -
there may be others similar that I have forgotten.


You know John, I forgot that you hangout here, too.
I am not even familiar with regex expressions. This is
a mod to allow a highlighter, noted below, to highlight Delphi
code.

The author was familiar with Delphi and got one working but
a few things were left out. The things you noted above and
asm blocks. I know that a parser will probably need to be
written to do the asm block kind of like how he did XML.

I know you know Delphi so would you be kind enough to help out?

http://www.dreamprojections.com/Synt...r/Default.aspx
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jon Maz | last post by:
Hi All, Am getting frustrated trying to port the following (pretty simple) function to CSharp. The problem is that I'm lousy at Regular Expressions.... //from...
6
by: Vishant | last post by:
Hi, I'm new to javascript and regEx and trying to solve the following problem. I have a function which validates the password if there is a number:...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
0
by: Chris McKenzie | last post by:
Hi, I'm using IE 6, and I'm doing some RegEx replacement on the client. Here's my code: regExStr = "\\d{2}:\\d{2}"; // where pattern matches ##:## regExStr += "(?=\\s)"; // and the next...
5
by: groovyd | last post by:
hi everyone, i have programmed quite extensively in C and C++ but am a newbie to javascript and am currently busy working my way through 'JavaScript: The Definitive Guide', a great book infact. ...
1
by: Abhishek | last post by:
Hi I have tried one more javascript Validator Script to Validate the Money entered in to the TextBox. <script language='javascript'> function checkNumber(val,e){ if(window.event){ var strkeyIE...
5
by: Abhishek | last post by:
Hi this is my another validator in javascript to validate the Phone Number :-) <script language='javascript'> function funcCheckPhoneNumber(ctrtxtMobile,e){ if(window.event){ var strkeyIE =...
9
by: kummu4help | last post by:
can anyone give me a regex to validate the password with following conditions hope i am clear. i tried with ctype_alnum() function in php but it is accepting if all characters or either...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.