Specification of Ruby regex?

Discussion in 'Ruby' started by Ronald Pijnacker, Aug 25, 2003.

  1. 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.
     
    Ronald Pijnacker, Aug 25, 2003
    #1
    1. Advertising

  2. Ronald Pijnacker

    Tim Hunter Guest

    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/ProgrammingRuby/html/tut_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.
     
    Tim Hunter, Aug 26, 2003
    #2
    1. Advertising

  3. 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
     
    Gavin Sinclair, Aug 26, 2003
    #3
  4. Ronald Pijnacker

    Mark Slagell Guest

    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)
     
    Mark Slagell, Aug 26, 2003
    #4
  5. 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
     
    Florian Frank, Aug 26, 2003
    #5
  6. Ronald Pijnacker

    Mark Slagell Guest

    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?
     
    Mark Slagell, Aug 26, 2003
    #6
  7. Ronald Pijnacker

    ts Guest

    >>>>> "M" == Mark Slagell <> 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
     
    ts, Aug 26, 2003
    #7
  8. Ronald Pijnacker

    Xavier Noria Guest

    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
     
    Xavier Noria, Aug 26, 2003
    #8
  9. Ronald Pijnacker

    Hal Fulton Guest

    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
     
    Hal Fulton, Aug 27, 2003
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    794
    Reedick, Andrew
    Jul 1, 2008
  2. David Ross

    Ruby Specification

    David Ross, Jul 19, 2004, in forum: Ruby
    Replies:
    26
    Views:
    365
    Lothar Scholz
    Jul 21, 2004
  3. Vasco Andrade e Silva

    Ruby Lex Specification

    Vasco Andrade e Silva, Oct 30, 2007, in forum: Ruby
    Replies:
    4
    Views:
    164
    Gene Tani
    Oct 31, 2007
  4. Shugo Maeda

    [ANN] Ruby draft specification

    Shugo Maeda, Dec 1, 2009, in forum: Ruby
    Replies:
    5
    Views:
    181
    Ryan Davis
    Dec 2, 2009
  5. Shugo Maeda

    The Final Draft Ruby Specification

    Shugo Maeda, Sep 22, 2010, in forum: Ruby
    Replies:
    0
    Views:
    132
    Shugo Maeda
    Sep 22, 2010
Loading...

Share This Page