Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Specification of Ruby regex?

Reply
Thread Tools

Specification of Ruby regex?

 
 
Ronald Pijnacker
Guest
Posts: n/a
 
      08-25-2003
Hi all,

I was just wondering... Is there any place where Ruby's Regex
capabilities are described?

E.g. it seems that /\w{3}/ matches at least three consecutive characters,
but I do not seem to be able to locate any exact documentation on this.

Any idea's?

Ronald.

 
Reply With Quote
 
 
 
 
Tim Hunter
Guest
Posts: n/a
 
      08-26-2003
On Tue, 26 Aug 2003 16:15:38 +0900, Ronald Pijnacker wrote:

>> > Hi all,
>> >
>> > I was just wondering... Is there any place where Ruby's Regex
>> > capabilities are described?
>> >
>> > E.g. it seems that /\w{3}/ matches at least three consecutive
>> > characters, but I do not seem to be able to locate any exact
>> > documentation on this.
>> >
>> > Any idea's?

>>
>> Pickaxe is your best friend (ideally, the hardcopy). Some information
>> may be found here:
>> http://www.ruby-doc.org/docs/Program..._stdtypes.html
>>
>> Scroll down to "Regular Expressions" sections.
>>
>> Gennady.

>
> There is certainly a lot of information there, but I have the feeling that
> there are things not discussed. My example "r {m}" is not mentioned as
> such, but works anyway.
>
> A better example would have been /o . I have seen it being used, but it is
> not documented. If it does what I've been told it does, it is good to know
> about.
>
> Another is /(?: ...)/ . It seems to work, but also is not documented.
> Aparently the Pickaxe book is not exhaustive.
>
> As I am currently reading "Mastering Regular Expressions", I started
> wondering what exacly is or is not supported by Ruby.
>
> Ronald.


In the paper version of the Pickaxe r{m} is described on
page 61. Extensions such as (?:...) on pp. 209-211.

My online version of the Pickaxe (from ruby-doc.org) documents both as
well. For the extensions, click The Ruby Language in the TOC and scroll
down to the Extensions section. Repetition (r{m}) is documented in
Standard Types.
 
Reply With Quote
 
 
 
 
Gavin Sinclair
Guest
Posts: n/a
 
      08-26-2003
On Tuesday, August 26, 2003, 10:18:24 PM, Emmanuel wrote:

> btw, since there is a thread about that, i wanted to ask:
> does ruby support named matches (sorry i don't know the proper terminology)?
> C# does it like this:
> "(?<year>\d{4})-(?<month>\d{1,2})-(?<day>\d{1,2})"


> matches "2002-4-6"
> and then in my match groups i have "year", "month", "day".


> (looked in pickaxe + google ruby "regexp match group")


I'm 99.99% sure it doesn't.

Gavin



 
Reply With Quote
 
Mark Slagell
Guest
Posts: n/a
 
      08-26-2003
Gavin Sinclair wrote:
> On Tuesday, August 26, 2003, 10:18:24 PM, Emmanuel wrote:
>
>
>>btw, since there is a thread about that, i wanted to ask:
>>does ruby support named matches (sorry i don't know the proper terminology)?
>>C# does it like this:
>>"(?<year>\d{4})-(?<month>\d{1,2})-(?<day>\d{1,2})"

>
>
>>matches "2002-4-6"
>>and then in my match groups i have "year", "month", "day".

>
>
>>(looked in pickaxe + google ruby "regexp match group")

>
>
> I'm 99.99% sure it doesn't.
>
> Gavin
>
>
>


Is this helpful at all?

year, month, day =
/(\d{4})-(\d{1,2})-(\d{1,2})/.match(s).to_a


(where s is the string to be matched)



 
Reply With Quote
 
Florian Frank
Guest
Posts: n/a
 
      08-26-2003
On 2003-08-26 21:56:39 +0900, Mark Slagell wrote:
> year, month, day =
> /(\d{4})-(\d{1,2})-(\d{1,2})/.match(s).to_a
> (where s is the string to be matched)



You probably meant to write this:

year, month, day = /(\d{4})-(\d{1,2})-(\d{1,2})/.match(s).captures


--
Claiming Java is easier than C++ is like saying that K2 is shorter than
Everest.
-- Larry O'Brian

 
Reply With Quote
 
Mark Slagell
Guest
Posts: n/a
 
      08-26-2003
Florian Frank wrote:
> On 2003-08-26 21:56:39 +0900, Mark Slagell wrote:
>
>>year, month, day =
>> /(\d{4})-(\d{1,2})-(\d{1,2})/.match(s).to_a
>>(where s is the string to be matched)

>
>
>
> You probably meant to write this:
>
> year, month, day = /(\d{4})-(\d{1,2})-(\d{1,2})/.match(s).captures


um, no, I wrote what I meant, but is something wrong with to_a there?




 
Reply With Quote
 
ts
Guest
Posts: n/a
 
      08-26-2003
>>>>> "M" == Mark Slagell <(E-Mail Removed)> writes:

M> um, no, I wrote what I meant, but is something wrong with to_a there?

it add $&

svg% ruby -e 'p /.(.)/.match("ab").to_a'
["ab", "b"]
svg%

svg% ruby -e 'p /.(.)/.match("ab").captures'
["b"]
svg%




Guy Decoux

 
Reply With Quote
 
Xavier Noria
Guest
Posts: n/a
 
      08-26-2003
On Tuesday 26 August 2003 18:12, Gennady wrote:

> m Multiline Mode. Normally, ``.'' matches any character except
> a newline. With the /m option, ``.'' matches any character.


Now that we are on it and just out of curiosity is there any particular
reason /m is Perl's /s?

On the other hand, the interpreter does not complain with /s so looks
like an undocumented (AFAIK) option. If it is public, what's its
meaning?

-- fxn


 
Reply With Quote
 
Hal Fulton
Guest
Posts: n/a
 
      08-27-2003
Ronald Pijnacker wrote:
> Hi,
>
> Thanks for all the feedback. Apparently I have to increase my search
> capabilities in ProgrammingRuby, because there are things documented
> that I could not find .


There's a reasonably good summary in chapter 1 of _The Ruby Way_.
Only a page or two as I recall, but it does have one or two items
not in the Pickaxe.

Hal


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Final Draft Ruby Specification Shugo Maeda Ruby 0 09-22-2010 01:02 AM
[ANN] Ruby draft specification Shugo Maeda Ruby 5 12-02-2009 07:17 PM
Ruby Lex Specification Vasco Andrade e Silva Ruby 4 10-31-2007 06:44 AM
Ruby Specification David Ross Ruby 26 07-21-2004 09:43 AM
Creating Library and Config Specification Roberto Gallo VHDL 0 11-19-2003 01:11 AM



Advertisments