f



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/SyntaxHighlighter/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;'
0
Mr
2/1/2005 2:55:14 PM
comp.lang.javascript 38370 articles. 0 followers. javascript4 (1315) is leader. Post Follow

2 Replies
2704 Views

Similar Articles

[PageSpeed] 6

JRS:  In article <1107269716.711be950c458361567b8868ee0225138@teranews>,
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/SyntaxHighlighter/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.
0
Dr
2/1/2005 9:12:55 PM
<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/SyntaxHighlighter/Default.aspx
0
Mr
2/2/2005 2:52:01 PM
Reply:

Similar Artilces:

tricky javascript problem requires javascript guru !
Hi, I am complete JavaScript novice and would really appreciate some help with this code: ===================================================================== <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!--#include file="Connections/ssdb.asp" --> <% Dim rs_news_edit Dim rs_news_edit_numRows Set rs_news_edit = Server.CreateObject("ADODB.Recordset") rs_news_edit.ActiveConnection = MM_ssdb_STRING rs_news_edit.Source = "SELECT * FROM tblnews" rs_news_edit.CursorType = 0 rs_news_edit.CursorLocation = 2 rs_news_edit.LockType = 1 r...

javascript within a javascript
Hello, I have a multi-frame page. The frames are named Frame_1, Frame_2 and Frame_3. Frame_1 has a drop down box. When a value is selected in this drop down box, Frame_2 is updated using an asp file (as I have to read from a back-end access database). In turn in the asp file, I have a Body onload tag to execute a javascript function within Frame_2. this function updates the contents of Frame_3. Till now this is working fine. Here is the problem. Frame_3 has a form with a radio button. When a radio button is selected, I want that a function be executed in Frame_3. However since conte...

regex and Javascript
Hi - I've never tried using regular expressions with JS. Can someone help me with a simple one? I have a field that a user inputs that looks for an integer, or a some integers with a decimal then does some calculations and converts it to currency. Problem is, that if i have to recalculate, that field now has a "$" in it which throws off calculations. I'd like to look at the field and if there is a "$", strip it out, do the calculations, etc. So, something like: function getDollar() { myAmount = window.document.form.amount.value; //here is where i want to look f...

regEx in Javascript
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: ------------------------------------------------- function findNumeric(str_obj){ regEx = /\d/; if (str_obj.match(regEx)) return true; else return false; } -------------------------------------------------- The problem arises when I put a password with a space in between e.g: 'test test1'. The fucntion returns false. I've tried '\s' in the regEx but the user can put the space anywhere.. Any idea how to sol...

Javascript and IE? Javascript and C#?
While my question might be simple, the environment around it is terribly messy and so I will try to keep this clear and simple by only including the relevant code - however, as I will soon suggest, I worry that the problem isnt in what would seem to be the relevant code but instead is lost somewhere in the do-and-donts of the peripheral code. So at the end, i'll try to include all the affected code and you can see if any of its actually relevant. I know there is a lot going on... sorry, but I tried to write this clearly. So here is what I imagine to be relevant. I'm working with a pa...

JavaScript Regex
Dear JavaScripters: I have not found quite the detail that I need for regexes. If you have a URL to a good site, please post it. In particular, how do I group subexpressions? I wish to parse a string to see if it is a valid fixed-decimal value. I start with /^ How do I check a set of characters optionally? I want to check for a sign character. The string might start with "+" or "-", but if it starts with neither, that is fine. Do I leave an empty choice in a parens set? Is it then ([+-]|) or [+-]? ? Then come...

a javascript problem
In IE this javascript cod for Date works perfectly, for a eksample: 25.12.2004. but in other Internet Viewers like Firefox or Natescape, it writes 25.12.104. Can enybody help me. And Happy Christmas to you all! here is the code myvar = new Date(); Month = (myvar.getMonth() + 1) Year = (myvar.getYear()) if (Month == 1) {WordMonth = "1";} if (Month == 2) {WordMonth = "2";} if (Month == 3) {WordMonth = "3";} if (Month == 4) {WordMonth = "4";} if (Month == 5) {WordMonth = "5";} if (Month == 6) {WordMonth = "6";} if (Month == 7) {WordM...

Javascript problem.
Try out the code below in an HTML file please. The problem is with the javascript. I can't get the body to change. The code below is PHP generated. Firefox says the problem is show() does not exist AFTER I click on the link display[ link displayed says: test ] <html> <script> function show( s ){ document.write("<table><tr><td>"+ body( s ) +"</td></tr></table>"); return 0; } function body( s ){ t = ' '; if ( s == "home" ){ t += "hi home<BR><BR>";t += "<a href=\&quo...

Javascript problem?
Hello, I have a small javascript on page that seems to affect the spacing further down on the page. That is, I have a large space between two unrelated HTML sections and when I remove the script, the space goes away. The page does validate with or without the script. You can see this on a test page at http://www.usernomics.com/ergonomic-products-data%20NEW.html . Note the space between the red text and the first table. The javascript is below. Can anyone see what might be causing the problem? Thanks, Bob The section containing the javascript looks like this: ...

its a javascript problem
I'll really appreciate if some could help me on a javascript issue I want to check a form text-box that wheather its an array of form-fields with same name or its a single though i think i m asking in wrong room but i know there must b some one who can help me uday wrote: > I'll really appreciate if some could help me on a javascript issue > > I want to check a form text-box that wheather its an array of > form-fields with same name or its a single > > though i think i m asking in wrong room but i know there must b some > one who can help me ...

Javascript Problem!
I am developing a site at http://www.nwlmi.org.uk The problem lies with the CSS/XHTML Menu which relies on JavaScript to open and close the sections. The parent sections open and close fine but when you click on one of the subsection items and go to the desired page the menu fails to remain open. The javascript code is embeded inthe html for reference. Is this a JS issue I wonder. The original script/code derived from Alsacreations but there is no documentation to aid this problem. Thanks in advance for any tips :) Chris cedwa wrote: > I am developing a site at http://www.nwlmi.org....

problems with JavaScript
Hi, I need help to JavaScript. I am new to this, and am trying to the page online ASAP. I have two submit buttons on one form, and each button will have to do different things. I named both button "but1". The first button has the value "Continue", the second button has the value "new page". If someone click on the button with the value "Continue", I need to check if certain information has been filled in before proceeding, and if yes, I need to go to page1.php (which is the second page of the form) and I have to save the result o...

regex in javascript
Hi folks, I'm trying to learn and understand regex in javascript for web form validation. In trying to write a piece of script to validate an email address I came up with the following: function isEmail(input) { var re =/^\w([\.\-]\w)*@\w([\.\-]\w)+$/ if (!re.exec(input)) { return false } } This is then referred to as : if (!isEmail(document.form.mailfrom.value)) { alert("This does not look like an email address") } etc. Unfortunately it bombs on absolutely everything. Can anyone suggest why? As an aside, is there any trul...

dynamic load javascript from javascript
hi, from here: http://www.activewidgets.com/javascript.forum.6114.15/dynamic-load-javascript-from-javascript.html there is a method to load js from js, e.g. //--------------------------------------------------------------------------------------- var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'snip.js'; document.getElementsByTagName('head')[0].appendChild(script); //--------------------------------------------------------------------------------------- this method works great, but there is a bug(?) when using wit...

Web resources about - Javascript RegEx problem - comp.lang.javascript

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

Lightbox (JavaScript) - Wikipedia, the free encyclopedia
On a Lightbox-enabled page, a user can click an image to have it magnified in a Lightbox window, which resizes itself according to the size of ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
about dmoz - help Top : Computers : Programming : Languages : JavaScript : Tools : Obfuscators Tools for obfuscation/compression JavaScript code. ...

Facebook Open-Sources JavaScript Static-Type Checker Flow
The latest software to be open-sourced by Facebook is Flow , a static-type checker for JavaScript . (more…) New Career Opportunities Daily: ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

Quickstart: Facebook SDK for JavaScript
This quickstart will show you how to setup the SDK, load social plugins, trigger a dialog, and get it to make some basic Graph API calls.

Facebook App Devs Get Javascript
It has been an oft-lamented fact of the Facebook Platform thus far in its life that, in order to use all but the most simple of Javascript functionality–the ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken . blog.mozilla.org/research/2014/… ...

Resources last updated: 2/4/2016 1:04:45 PM