Ruby regex substition question

Status
Not open for further replies.

Nonapod

Ars Scholae Palatinae
697
I can't seem to find any info on RegEx pattern memory variables in Ruby.

In Perl if I want to save a part of pattern match to use at a later time, it can be done with (), and the pattern is then stored in special memory variables like $1, $2, $3 ect. Like for example if I wanted to substitute all the ending "s"'s from words, but only when the previous letter is not a vowel or another s.

In Perl:
Code:
$string =~ s/([^AaEeIiOoUuSs])[Ss][\b]/$1 /g;

I'd like to be able to do the same in Ruby, but

Code:
string.gsub(/([^AaEeIiOoUuSs])[Ss][\b]/,"$1 "/)

doesn't work (it just replaces matches with $1). Does Ruby even have special variables like that?
 
Status
Not open for further replies.