ShowUsYour<Blog>

Irregular expressions regularly

Regex's in JScript.NET

I started reading JScript.NET Programming today:

This language offers a very different way to write .NET code. I'm reading it mostly for two reasons, A) I like the authors' manner of offering more abstract samples and sensible advice than you tend to get in a book of this size; B) so that I can learn about how Regular Expressions are implemented within the JScript.NET language. I'm keen to write a dirt simple regex based routine using to lex through a string with multiple regex's within a loop similar to how you might do it using Perl; it might be nice if you could write and compile regex parsing routines in a js module and consume it from an other language of choice.

So, anyway, I started on Chapter 12 : Regular Expressions and wrote my first app. with it tonight...

import System ;
function DoMatch( str ) {
    var re = /\w+/g ;
    while( re.test( str ) ) {
        Console.WriteLine( 
            RegExp.index + " - " + RegExp.lastIndex +
            "\t" + RegExp.lastMatch + "." ) ;
    }
}
DoMatch( "This is a group of words" ) ;

 

C:\>jsc /t:exe /fast- JS_One.js
Microsoft (R) JScript .NET Compiler version 7.10.3052
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 1996-2002. All rights reserved.

C:\>JS_One
0 - 4   This.
5 - 7   is.
8 - 9   a.
10 - 15 group.
16 - 18 of.
19 - 24 words.

 

Posted: Apr 09 2004, 03:16 PM by digory | with 5 comment(s)
Filed under:

Comments

Brian LeRoux said:

Sorry for the OT but how did you highlight that code and command line? -- looks great!
# April 13, 2004 2:21 PM

Darren Neimke said:

# April 13, 2004 6:53 PM

Brian LeRoux said:

Thanks!
# April 13, 2004 7:55 PM

kikus said:

интеретсно написано

# June 15, 2010 1:53 AM

kikus said:

интеретсный блог почему только так мало читателей на нём

# June 15, 2010 2:03 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)