[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Named backreferences with Oniguruma

Berger, Daniel

7/27/2006 1:11:00 PM

Hi all,

Ruby 1.8.4
Oniguruma 2.5.6

I'm trying to figure out how to get at named backreferences with
Oniguruma, but I'm having some problems figuring it out. Here's the
interface I would *like* to have:

# pseudo.rb
str = "hello world"
reg = /^(?<first>\w+?)\s(?<last>\w+)$/

match = reg.match(str)

first = match[:first]
last = match[:last]

But this doesn't work - I mean, the regex works, but the way I'm trying
to get at the backreferences does not. Nor does there appear to be
anything like Python's MatchData#groupdict() method (which returns a
hash).

How do I get at the named backreferences from the MatchData object? Is
there a way?

Thanks,

Dan


This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.

4 Answers

ts

7/27/2006 1:21:00 PM

0

>>>>> "B" == Berger, Daniel <Daniel.Berger@qwest.com> writes:

B> reg = /^(?<first>\w+?)\s(?<last>\w+)$/

moulon% cat b.rb
#!/usr/bin/ruby
str = "hello world"
reg = /^(?<first>\w+?)\s(?<last>\w+)$/

match = reg.match(str)

first = match[:first]
last = match[:last]

p first,last
moulon%

moulon% ruby -v b.rb
ruby 1.9.0 (2006-07-14) [i686-linux]
"hello"
"world"
moulon%

moulon% grep ONIGURUMA_VERSION ruby/oniguruma.h
#define ONIGURUMA_VERSION_MAJOR 4
#define ONIGURUMA_VERSION_MINOR 0
#define ONIGURUMA_VERSION_TEENY 3
moulon%


Guy Decoux

Nobuyoshi Nakada

7/27/2006 1:33:00 PM

0

Hi,

At Thu, 27 Jul 2006 22:11:02 +0900,
Berger, Daniel wrote in [ruby-talk:204263]:
> Ruby 1.8.4
> Oniguruma 2.5.6

Not 1.9? That combination isn't supported officially.

> I'm trying to figure out how to get at named backreferences with
> Oniguruma, but I'm having some problems figuring it out. Here's the
> interface I would *like* to have:

MatchData#[] in 1.8 doesn't take symbols.

--
Nobu Nakada

Berger, Daniel

7/27/2006 1:35:00 PM

0

nobu@ruby-lang.org wrote:
> Hi,
>
> At Thu, 27 Jul 2006 22:11:02 +0900,
> Berger, Daniel wrote in [ruby-talk:204263]:
>> Ruby 1.8.4
>> Oniguruma 2.5.6
>
> Not 1.9? That combination isn't supported officially.

Oh, I didn't know that.

>> I'm trying to figure out how to get at named backreferences with
>> Oniguruma, but I'm having some problems figuring it out. Here's the
>> interface I would *like* to have:
>
> MatchData#[] in 1.8 doesn't take symbols.
>

Couldn't it be added? I mean, it's a custom re.c anyway, isn't it?

Thanks,

Dan


This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.

Nobuyoshi Nakada

7/27/2006 2:13:00 PM

0

Hi,

At Thu, 27 Jul 2006 22:35:18 +0900,
Daniel Berger wrote in [ruby-talk:204267]:
> >> I'm trying to figure out how to get at named backreferences with
> >> Oniguruma, but I'm having some problems figuring it out. Here's the
> >> interface I would *like* to have:
> >
> > MatchData#[] in 1.8 doesn't take symbols.
> >
>
> Couldn't it be added? I mean, it's a custom re.c anyway, isn't it?

To which? Oniguruma doesn't contain the patch for 1.8?

--
Nobu Nakada