Regex Help Please

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 :slight_smile:

            \)                          #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 …

Hi,
— “Matthew, Graeme” Graeme.Matthew@mercer.com
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 :slight_smile:
) #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.

One way to find multiple occurrences would be:

 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.

“Park Hee-Sob” heesobpark@yahoo.com wrote in message

You can do it using pcre.

Hello Park,

When I go to your link:

http://home.nownuri.net/~phasis/pcre.tar.gz

I get an error , which I believe is in Korean :
HTTP 404 - ??? ?? ? ??
Internet Information Services

Do you know if I can get Windows binaries of pcre somewhere ?
Or do I have to compile it from source.
Thanks,

– shanko

Hi,

“Shashank Date” sdate@kc.rr.com wrote in message
news:qTxM9.413$P36.29950@twister.rdc-kc.rr.com

“Park Hee-Sob” heesobpark@yahoo.com wrote in message

You can do it using pcre.

Hello Park,

When I go to your link:

http://home.nownuri.net/~phasis/pcre.tar.gz

I get an error , which I believe is in Korean :
HTTP 404 - ??? ?? ? ??
Internet Information Services

Do you know if I can get Windows binaries of pcre somewhere ?
Or do I have to compile it from source.
Thanks,

– shanko

Sorry, my typo.
It is http://home.nownuri.net/~phasis/pcre/pcre.tar.gz

In Windows
You need to download
http://home.nownuri.net/~phasis/pcre/pcre-3.9-bin.zip
and
http://home.nownuri.net/~phasis/pcre/pcre-3.9-lib.zip

Park Heesob

“Park Heesob” phasis@kornet.net wrote in message

It is http://home.nownuri.net/~phasis/pcre/pcre.tar.gz

In Windows
You need to download
http://home.nownuri.net/~phasis/pcre/pcre-3.9-bin.zip
and
http://home.nownuri.net/~phasis/pcre/pcre-3.9-lib.zip

Thanks a lot !
– shanko