From: "Mauricio Fernández" Date: 2003-05-26T16:12:17+09:00 Subject: Re: Modified "showRE" anomalies On Mon, May 26, 2003 at 03:18:10PM +0900, Richard wrote: > I modified "showRE" demonstrated in the online version of Programming > Ruby. My purpose was to have what struck me as a more convenient way > of analyzing the nuances of Ruby's implementation of Regular > Expressions. My mod is: > > def applyRE(a,re) > if a =~ re > puts "Val '#{a}', Pat '#{re}' ==> #{$`}<<#{$&}>>#{$'}" > else > puts "Val '#{a}', Pat '#{re}' ==> no match" > end > end > > v1 = '12.34' > p1 = '/^\d*\.?/' > > applyRE(v1, /^\d*\.?/) # Val '12.34', Pat '#' ==> > <<12.>>34 > applyRE(v1, p1) # Val '12.34', Pat '/^\d*\.?/' ==> no match batsman@tux-chan:/tmp$ expand -t2 al.rb def applyRE(a,re) if a =~ re puts "Val '#{a}', Pat '#{re.source}' ==> #{$`}<<#{$&}>>#{$'}" else puts "Val '#{a}', Pat '#{re.source}' ==> no match" end end v1 = '12.34' p1 = /^\d*\.?/ # this a Regexp not a String! applyRE(v1, /^\d*\.?/) applyRE(v1, p1) batsman@tux-chan:/tmp$ /usr/bin/ruby -v ruby 1.6.8 (2002-12-24) [i386-linux] batsman@tux-chan:/tmp$ /usr/bin/ruby al.rb Val '12.34', Pat '^\d*\.?' ==> <<12.>>34 Val '12.34', Pat '^\d*\.?' ==> <<12.>>34 batsman@tux-chan:/tmp$ expand -t2 ak.rb def applyRE(a,re) if a =~ re puts "Val '#{a}', Pat '#{re}' ==> #{$`}<<#{$&}>>#{$'}" else puts "Val '#{a}', Pat '#{re}' ==> no match" end end v1 = '12.34' p1 = /^\d*\.?/ applyRE(v1, /^\d*\.?/) applyRE(v1, p1) batsman@tux-chan:/tmp$ ruby -v ruby 1.8.0 (2003-03-03) [i686-linux] batsman@tux-chan:/tmp$ ruby ak.rb Val '12.34', Pat '(?-mix:^\d*\.?)' ==> <<12.>>34 Val '12.34', Pat '(?-mix:^\d*\.?)' ==> <<12.>>34 Regexp#to_s has changed. -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com - long f_ffree; /* free file nodes in fs */ + long f_ffree; /* freie Dateiknoten im Dateisystem */ -- Seen in a translation