At this point $1 is nil, which is why you get the error. You have to keep in
mind that arguments are evaluated before the method is called and $1 will
only have value after that. You need to use '\1' instead of $1.
The problem it's not the regex, it's the second parameter, try instead:
string.gsub(/(\w{7}).+/, '\1')
This supposing you want ever the first seven chars, if you want the
characters before because they can be variable, try this regex:
string.gsub(/(\w*)(_.*)*\..+/, '\1')
I'm not mastered the regular expressions, any corrections appreciated.
Regards,
Jovino
···
-----Mensaje original-----
De: Gilbert Rebhan [mailto:mailforgilbert@gmx.de]
Enviado el: sábado, 22 de septiembre de 2007 11:55
Para: ruby-talk ML
Asunto: regex problem with gsub
Hi,
i have a dir like that and need the
first part of the first filename =
At this point $1 is nil, which is why you get the error. You have to keep in mind that arguments are evaluated before the method is called and $1 will only have value after that. You need to use '\1' instead of $1.
Thanks!!
Works now. I'm still not sure, when to use \1 and when to use $1