From: "Matthew, Graeme" Date: 2002-12-20T11:16:56+09:00 Subject: Regex Help Please This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C2A7CD.53D8F27A Content-Type: text/plain Hi All, thanks for your comments, that have really helped, ill correct my incorrect terminology, greedy is /m, sorry. Lets me re-phrase, perhaps the source below (Thanks Shashank Date) will be more clearer. now from the example you see below I need to find multiple occurrences of the same pattern within the string, looking below there are two function definitions, therefore I don't want it to match the first I want it to continue until no further matching takes place. prog = 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 (.*?) #Followed by characters(name of token) \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 = "PRIVATE function test() \n some code here \n End function\n\nPRIVATE function testing() \n some code here \n End function" m = prog.match(s) if m p "#{m[0]}\n#{m[1]}" else puts 'Did not match!' end many thanks ... ------_=_NextPart_001_01C2A7CD.53D8F27A Content-Type: text/html Content-Transfer-Encoding: quoted-printable

Hi All, thanks for your comments, that have really = helped, ill correct my incorrect terminology, greedy is /m, = sorry.

 

Lets me re-phrase, perhaps the source below (Thanks = Shashank Date) will be more clearer. now from the example you see below I need = to find multiple occurrences of the same pattern within the string, looking = below there are two function definitions, therefore I don't want it to match the first I want it to continue until no further matching takes = place.

 

prog =3D Regexp.compile('

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

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

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

         = ;       = \s*           &nb= sp;         =     #Followed by any whitesoace          &n= bsp;        

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

         = ;       = \s*           &nb= sp;         =     #Followed by whitespace, but its optional

         = ;       = \(           &nbs= p;         =      #Followed by an opening bracket - start of parameter enclosure

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

         = ;       = \)           &nbs= p;          =     #Followed by a closing bracket

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

         = ;       = end\s+\2          &nbs= p;     #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\n\nPRIVATE function testing() \n some code here \n End = function"

    m =3D = prog.match(s)

    if m

        p = "#{m[0]}\n#{m[1]}"

         = ;  

    else

        puts 'Did = not match!'

    end

 

many thanks ...

 

------_=_NextPart_001_01C2A7CD.53D8F27A--