perl pos function equivalent in ruby?

D

Dmitry V. Sabanin

What's the equivalent to perl's reexp pos function in ruby?
I don't know what perl's pos does, but here.
Look at MatchData:

$ ri MatchData
------------------------------------------------------------------------
class: MatchData
------------------------------------------------------------------------
MatchData is the type of the special variable $~, and is the type
of the object returned by Regexp#match and Regexp#last_match. It
encapsulates all the results of a pattern match, results normally
accessed through the special variables $&, $', $`, $1, $2, and so
on. Matchdata is also known as MatchingData.
 
J

John W. Long

----- "Dmitry V. Sabanin" wrote: -----
I don't know what perl's pos does, but here.
Look at MatchData:
. . .

I know about MatchData. Perl's pos function basically returns the position
of the end of the current match. Which sounds like MatchData#end, the
difference is you can set pos so that you specify the begining in the string
of the next search. I haven't seen anything in Ruby like this.

See http://www.perldoc.com/perl5.6/pod/func/pos.html .

___________________
John Long
www.wiseheartdesign.com
 
N

nobu.nokada

Hi,

At Fri, 9 Apr 2004 10:53:51 +0900,
John W. Long wrote in [ruby-talk:96846]:
I know about MatchData. Perl's pos function basically returns the position
of the end of the current match. Which sounds like MatchData#end, the
difference is you can set pos so that you specify the begining in the string
of the next search. I haven't seen anything in Ruby like this.

Use 2nd argument to String#index.
 
R

Robert Klemme

Hi,

At Fri, 9 Apr 2004 10:53:51 +0900,
John W. Long wrote in [ruby-talk:96846]:
I know about MatchData. Perl's pos function basically returns the position
of the end of the current match. Which sounds like MatchData#end, the
difference is you can set pos so that you specify the begining in the string
of the next search. I haven't seen anything in Ruby like this.

Use 2nd argument to String#index.

I wonder what he needs that for. Often that can be dealt with by changing
the RX in a way that String#scan is sufficient.

robert
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top