From: Shashank Date Date: 2002-12-20T10:58:13+09:00 Subject: Re: regex help please please ! This is a multi-part message in MIME format. ------=_NextPart_000_0105_01C2A797.1A6EE250 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable How about: prog =3D Regexp.compile(' (Private|Public)? #Look for Private or Public = identifier but its optional \s* #Followed by any whitesoace (sub|function) #Followed by the word Sub or = Function \s* #Followed by any whitesoace = =20 (.*?) #Followed by characters(name of = token) =20 \s* #Followed by whitespace, but its = optional \( #Followed by an opening bracket = - start of parameter enclosure (.*?) #Followed by a whole lot of text = ie parameters :-) \) #Followed by a closing bracket (.*?) #Followed by a whole lot of text = (the code) end\s+\2 #Followed by the word End = followed by Sub or Function ' , Regexp::MULTILINE + Regexp::EXTENDED + = Regexp::IGNORECASE) s =3D "PRIVATE function test() \n some code here \n End function" m =3D prog.match(s) if m p m[0] else puts 'Did not match!' end s =3D "PRIVATE Sub test() \n some code here \n End function" m =3D prog.match(s) if m p m[0] else puts 'Did not match!' end Let me know if that works for you. I have only tested it on ruby 1.7.3 = (2002-11-17) [i386-mswin32] HTH, -- shanko "Matthew, Graeme" wrote in message = news:AFB901DF1A6CD411A3AD00D0B781F8E5049CA1B0@wmelntms01.au.wmmercer.com.= ... Hi All Please could someone assist as im now bald with a pile of hair around = my chair ! How does one do greedy regex's in ruby ? in Perl / Python one has = access to the /s or .DOTALL option but in ruby I cannot get a greedy = effect. For example in Python to analyse a, yes im sorry visual basic file and = tokenize it I can do the following: prog =3D re.compile(r""" (Private|Public)? #Look for Private or Public = identifier but its optional \s* #Followed by any whitesoace (sub|function) #Followed by the word Sub or = Function \s* #Followed by any whitesoace = =20 (.*?) #Followed by characters(name of = token) =20 \s* #Followed by whitespace, but its = optional \( #Followed by an opening bracket - = start of parameter enclosure (.*?) #Followed by a whole lot of text = ie parameters :-) \) #Followed by a closing bracket (.*?) #Followed by a whole lot of text = (the code) end\s+(sub|function) #Followed by the word End followed = by Sub or Function """,re.DOTALL + re.IGNORECASE + re.VERBOSE) =20 result =3D prog.findall(data) Thanks Graeme __ ********************************************** This e-mail and any attachments may be confidential or legally = privileged. If you received this message in error or are not the intended = recipient, you should destroy the e-mail message and any attachments or copies, and = you are prohibited from retaining, distributing, disclosing or using any = information contained herein. Please inform us of the erroneous delivery by return e-mail.=20 Thank you for your cooperation. ********************************************** ec03/04 ------=_NextPart_000_0105_01C2A797.1A6EE250 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
How about:
 
    prog =3D=20 Regexp.compile('
         = ;      =20 (Private|Public)?       #Look for Private = or=20 Public identifier but its=20 optional
          &= nbsp;    =20 \s*           &nbs= p;        =20 #Followed by any=20 whitesoace
          = ;     =20 (sub|function)          = #Followed=20 by the word Sub or=20 Function
          &= nbsp;    =20 \s*           &nbs= p;        =20 #Followed by any=20 whitesoace          &nb= sp;        =20
           &nb= sp;   =20 (.*?)           &n= bsp;      =20 #Followed by characters(name of=20 token)           &= nbsp;      =20
           &nb= sp;   =20 \s*           &nbs= p;        =20 #Followed by whitespace, but its=20 optional
          &= nbsp;    =20 \(            = ;         =20 #Followed by an opening bracket - start of parameter=20 enclosure
          =      =20 (.*?)           &n= bsp;      =20 #Followed by a whole lot of text ie parameters=20 :-)
           =     =20 \)            = ;         =20 #Followed by a closing=20 bracket
          &n= bsp;    =20 (.*?)           &n= bsp;      =20 #Followed by a whole lot of text (the=20 code)
          &nbs= p;    =20 end\s+\2           = ;    =20 #Followed by the word End followed by Sub or=20 Function
          &= nbsp;    =20 ' , Regexp::MULTILINE + Regexp::EXTENDED + = Regexp::IGNORECASE)
 

    s =3D "PRIVATE function test() \n some code = here \n=20 End function"
    m =3D = prog.match(s)
    if=20 m
        p = m[0]
   =20 else
        puts 'Did not=20 match!'
    end
 

    s =3D "PRIVATE Sub test() \n some code here = \n End=20 function"
    m =3D = prog.match(s)
    if=20 m
        p = m[0]
   =20 else
        puts 'Did not=20 match!'
    end
 
Let me know if that works for you. I have only tested it on ruby = 1.7.3=20 (2002-11-17) [i386-mswin32]
 
HTH,
-- shanko
 
"Matthew, Graeme" <Graeme.Matthew@mercer.com&g= t;=20 wrote in message news:AFB901DF1A6CD411A3AD00D0B781F8E5049CA1B0@wmelntms01.au.wmme= rcer.com...

Hi All

 

 

Please could someone = assist as im=20 now bald with a pile of hair around my chair !

 

How does one do greedy = regex's in=20 ruby ? in Perl / Python one has access to the /s or .DOTALL option but = in ruby=20 I cannot get a greedy effect.

 

For example in Python to = analyse=20 a, yes im sorry visual basic file and tokenize it I can do the=20 following:

 

prog =3D=20 re.compile(r"""

           = =20 (Private|Public)?       #Look for = Private or=20 Public identifier but its optional

           = =20 \s*           =20          #Followed by any = whitesoace

           = =20 (sub|function)          = #Followed=20 by the word Sub or Function

           = =20 = \s*           &nbs= p;        =20 #Followed by any=20 = whitesoace          &nb= sp;        =20

           = =20 = (.*?)           &n= bsp;      =20 #Followed by characters(name of=20 = token)           &= nbsp;      =20

           = =20 = \s*           &nbs= p;        =20 #Followed by whitespace, but its optional

           = =20 = \(            = ;         =20 #Followed by an opening bracket - start of parameter=20 enclosure

           = =20 = (.*?)           &n= bsp;      =20 #Followed by a whole lot of text ie parameters :-)

           = =20 = \)            = ;         =20 #Followed by a closing bracket

           = =20 = (.*?)           &n= bsp;      =20 #Followed by a whole lot of text (the code)

           = =20 end\s+(sub|function)    #Followed by the word End = followed by=20 Sub or Function

           = =20 """,re.DOTALL + re.IGNORECASE + re.VERBOSE)

       =20

       =20 result =3D prog.findall(data)

 

 

 

Thanks

 

 

Graeme

 

 

 

__



**********************************************

This e-mail and any attachments may be = confidential=20 or legally privileged.

If you received this message in error = or are not=20 the intended recipient, you

should destroy the e-mail message and = any=20 attachments or copies, and you are

prohibited from retaining, = distributing, disclosing=20 or using any information

contained herein. Please inform us of = the erroneous=20 delivery by return

e-mail.


Thank you for your = cooperation.

**********************************************


ec03/04


------=_NextPart_000_0105_01C2A797.1A6EE250--