[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Question about regular expression

Gennady Bystritsky

1/17/2006 8:01:00 AM

^ as a first character inside [] indicates negation, for example [^abc] means a character other then 'a', 'b' or 'c'.


-----Original Message-----
From: Gennady Bystritsky
Sent: Mon 1/16/2006 23:47
To: ruby-talk ML
Subject: Re: Question about regular expression

^ means from the beginning of a line ($ - end of line).
* means that a preceding character or group may be repeated 0 or more times.

Gennady.


-----Original Message-----
From: Eric Luo [mailto:eric.wenbl@gmail.com]
Sent: Mon 1/16/2006 23:17
To: ruby-talk ML
Subject: Re: Question about regular expression

Thanks very much, I really appreatiate your help

It does work, but I couldn't figure out what the ^ and * do? could you
explain that in more detail?

Thanks


2006/1/17, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov>:
>
> On Tue, 17 Jan 2006, Eric Luo wrote:
>
> > Thanks for your replay.
> >
> > To make the problem clear.
> > I want to only change the regular expression, but not the code to
> implement
> > this function.
> > Actually, the regular expression comes from a configurable table. I'll
> be
> > supposed to only have the privilege to update the table.
> >
> > So What I really want is a alternative way to in place of the regular
> > expression
> > (?<!STR )SNPB
>
> harp:~ > cat a.rb
> strings = "STR SNPB", "STR", "SNPB"
>
> re = %r/^ (?: (?:[^S]) | (?:S[^T]) | (?:ST[^R]) )* SNPB /ox
>
> strings.each do |string|
> permutations = string, "foo #{ string }", "#{ string } bar", "foo #{
> string } bar"
> permutations.each do |permutation|
> puts "<#{ permutation }> matches" if re.match permutation
> end
> end
>
> harp:~ > ruby a.rb
> <SNPB> matches
> <foo SNPB> matches
> <SNPB bar> matches
> <foo SNPB bar> matches
>
> hth.
>
> -a
> --
> strong and healthy, who thinks of sickness until it strikes like
> lightning?
> preoccupied with the world, who thinks of death, until it arrives like
> thunder? -- milarepa
>
>
>