From: Park Hee-Sob Date: 2002-12-20T12:16:17+09:00 Subject: Re: Regex Help Please Hi, --- "Matthew, Graeme" wrote: > 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. http://mailplus.yahoo.com