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
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.
many thanks …
You can do it using pcre.
require ‘pcre’
str = “PRIVATE Sub test() \n some code here \n End sub
PRIVATE Sub test2() \n some code here \n End
sub
PRIVATE function test3() \n some code here \n
End function”
test = str.pcre_match_all(/
(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
/x,PCRE_DOTALL|PCRE_MULTILINE|PCRE_CASELESS);
p test
Park Hesob
···
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
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)
while m
p m[0]
s = m.post_match
m = prog.match(s)
end
“Matthew, Graeme” Graeme.Matthew@mercer.com wrote in message
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.