[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Regular Expression matching biggest possible

Peter Michaux

4/1/2006 3:56:00 PM

Hi,

I would like to remove comments from a JavaScript file with a Ruby
script. I discovered that my regular expression matching seems to match
the biggest possible substring.

def show_regexp(a,re)
if a =~ re
"#{$`}<<#{$&}>>#{$'}"
else
"no match"
end
end
puts show_regexp("/* some comment */ some code /* some other comment
*/", /\/\*[\w\W]*\*\//)

This outputs

<</* some comment */ some code /* some other comment */>>

and I was hoping for it to find the individual comments.

<</* some comment */>> some code <</* some other comment */>>

What should my regular expression be?

Thanks,
Peter

4 Answers

Chris Alfeld

4/1/2006 4:10:00 PM

0

You can make a regexp non greedy with a ?, that is

/\/\*[\w\W]*?\*\//
^


Peter Michaux

4/1/2006 4:55:00 PM

0


Chris Alfeld wrote:
> You can make a regexp non greedy with a ?, that is
>
> /\/\*[\w\W]*?\*\//

Thanks Chris,

Now I can easily find what i need in the manual:)

Peter

Vassilis Rizopoulos

4/1/2006 6:41:00 PM

0

petermichaux@gmail.com wrote:
> Hi,
>
> I would like to remove comments from a JavaScript file with a Ruby
> script. I discovered that my regular expression matching seems to match
> the biggest possible substring.
Wow, I only had to wait 20 minutes before posting (or you could have
checked the regexp madness thread).
Seems today is greedy regexp day :)
V.-

--
http://www.braveworl...

____________________________________________________________________
http://www.f... - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.f... - free email service for the Greek-speaking.


The PHANTOM

9/16/2008 12:58:00 PM

0

On Sep 15, 2:41 am, "Roy Blankenship" <pointbla...@earthlink.net>
wrote:
> "Al. E. Gator Esq." <ObamaCroc08.net> wrote in messagenews:SqedncVQ4sIim1PVnZ2dnUVZ_hWdnZ2d@comcast.com...
>
>
>
>
>
>
>
> > "Roy Blankenship" <pointbla...@earthlink.net> wrote in message
> >news:E4-dnZ46nbdnIFDVnZ2dnUVZ_hSdnZ2d@earthlink.com...
>
> > > "Just Visiting" <nospam-webex...@sbcglobal.net> wrote in message
> > >news:8shqc4dj1lm8pkqgmt7laj89plbni6is3m@4ax.com...
>
> > > Maybe someday people will transcend all this "prayer" stuff and realize
> it
> > > is just us. It gets tiresome hearing people asking others to "pray" for
> > > them
> > > or their loved ones. When are you people going to wake up and realize
> you
> > > have been indoctrinated into a belief system designed to control you out
> > > of
> > > fear? How is the selling of "burning in Hell" different from your
> > > insurance
> > > man painting a picture of the financial disaster you would be in if you
> > > didn't buy insurance from him?
>
> > > I just went to my 40th high school reunion, one of the attendees had
> > > "received his calling" and is now a "minister". When someone asked him
> to
> > > "bless the reunion with a prayer", I actually felt offended. I wanted to
> > > say, "Hey, don't drag me into your bizarre voodoo bullshit". We had a
> > > customer recently who wouldn't buy a product he needed because it had
> > > "Voodoo" in the name. How ridiculous is that?
>
> > > No more ridiculous than praying for someone's safety to the unseen
> > > pie-in-the-sky.
>
> > logic and reason says you're right,
>
> > the unexplainable says you might be wrong
>
> > there is not enough evidence or information to prove either
>
> Ah, the unexplainable. There is that. I awoke one time and had a sense that
> my dead mother was going to appear to me, I walked to the front door, it was
> raining, I opened the inside door (there was a screen door), and after about
> 10 seconds, a lightning bolt hit the telephone pole across the street. The
> next day, I went and picked up a baseball bat-sized shard and kept it. I
> wonder if this means my mother is pissed off now that she can observe my
> daily activities?- Hide quoted text -
>
> - Show quoted text -

Prolly means you need to give up the gallon-a-day MD 20-20 habit.